Spaces:
Runtime error
Runtime error
Zengyf-CVer
commited on
Commit
•
7cea19b
1
Parent(s):
339f78e
app v02 update
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
# Streamlit YOLOv5 Model2X v0.
|
2 |
# 创建人:曾逸夫
|
3 |
-
# 创建时间:2022-07-
|
4 |
# 功能描述:多选,多项模型转换和打包下载
|
5 |
|
6 |
import os
|
@@ -41,14 +41,41 @@ def zipDir(origin_dir, compress_file):
|
|
41 |
zip.close()
|
42 |
|
43 |
|
44 |
-
# params_include_list = ["torchscript", "onnx", "openvino", "coreml", "saved_model", "pb", "tflite", "tfjs"]
|
45 |
-
def cb_opt(weight_name, btn_model_list, params_include_list
|
|
|
46 |
|
47 |
for i in range(len(btn_model_list)):
|
48 |
if btn_model_list[i]:
|
49 |
st.info(f"正在转换{params_include_list[i]}......")
|
50 |
s = time.time()
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
e = time.time()
|
53 |
st.success(f"{params_include_list[i]}转换完成,用时{round((e-s), 2)}秒")
|
54 |
|
@@ -59,7 +86,6 @@ def cb_opt(weight_name, btn_model_list, params_include_list):
|
|
59 |
def main():
|
60 |
with st.container():
|
61 |
st.title("Streamlit YOLOv5 Model2X")
|
62 |
-
st.subheader('创建人:曾逸夫(Zeng Yifu)')
|
63 |
st.text("基于Streamlit的YOLOv5模型转换工具")
|
64 |
|
65 |
st.write("-------------------------------------------------------------")
|
@@ -80,28 +106,59 @@ def main():
|
|
80 |
fb.close()
|
81 |
st.success(f"{weight_name}写入成功!")
|
82 |
|
|
|
|
|
|
|
83 |
st.text("请选择转换的类型:")
|
84 |
cb_torchscript = st.checkbox('TorchScript')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
cb_onnx = st.checkbox('ONNX')
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
cb_openvino = st.checkbox('OpenVINO')
|
87 |
-
|
88 |
cb_coreml = st.checkbox('CoreML')
|
89 |
cb_saved_model = st.checkbox('TensorFlow SavedModel')
|
90 |
cb_pb = st.checkbox('TensorFlow GraphDef')
|
91 |
cb_tflite = st.checkbox('TensorFlow Lite')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
# cb_edgetpu = st.checkbox('TensorFlow Edge TPU')
|
93 |
cb_tfjs = st.checkbox('TensorFlow.js')
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
btn_convert = st.button('转换')
|
96 |
|
97 |
btn_model_list = [
|
98 |
-
cb_torchscript, cb_onnx, cb_openvino, cb_coreml, cb_saved_model, cb_pb, cb_tflite, cb_tfjs]
|
99 |
|
100 |
params_include_list = [
|
101 |
"torchscript", "onnx", "openvino", "engine", "coreml", "saved_model", "pb", "tflite", "tfjs"]
|
102 |
|
103 |
if btn_convert:
|
104 |
-
cb_opt(weight_name, btn_model_list, params_include_list
|
|
|
105 |
|
106 |
st.write("-------------------------------------------------------------")
|
107 |
|
|
|
1 |
+
# Streamlit YOLOv5 Model2X v0.2
|
2 |
# 创建人:曾逸夫
|
3 |
+
# 创建时间:2022-07-17
|
4 |
# 功能描述:多选,多项模型转换和打包下载
|
5 |
|
6 |
import os
|
|
|
41 |
zip.close()
|
42 |
|
43 |
|
44 |
+
# params_include_list = ["torchscript", "onnx", "openvino", "engine", "coreml", "saved_model", "pb", "tflite", "tfjs"]
|
45 |
+
def cb_opt(device, imgSize, weight_name, btn_model_list, params_include_list, iou_conf, tflite_options, onnx_options,
|
46 |
+
torchscript_options):
|
47 |
|
48 |
for i in range(len(btn_model_list)):
|
49 |
if btn_model_list[i]:
|
50 |
st.info(f"正在转换{params_include_list[i]}......")
|
51 |
s = time.time()
|
52 |
+
if i == 0: # torchscript
|
53 |
+
os.system(
|
54 |
+
f"python export.py --device {device} --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]} "
|
55 |
+
+ "".join([f"--{x} " for x in torchscript_options]))
|
56 |
+
if i == 1: # onnx
|
57 |
+
os.system(
|
58 |
+
f"python export.py --device {device} --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]} "
|
59 |
+
+ "".join([f"--{x} " for x in onnx_options]))
|
60 |
+
if i == 3:
|
61 |
+
# TensorRT需要在GPU模式下导出
|
62 |
+
pass
|
63 |
+
# os.system(
|
64 |
+
# f"python export.py --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]} --device 0"
|
65 |
+
# )
|
66 |
+
elif i == 8: # tfjs
|
67 |
+
os.system(
|
68 |
+
f"python export.py --device {device} --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]} --iou-thres {iou_conf[0]} --conf-thres {iou_conf[1]}"
|
69 |
+
)
|
70 |
+
elif i == 7: # tflite
|
71 |
+
# 参考:https://github.com/zldrobit/yolov5
|
72 |
+
os.system(
|
73 |
+
f"python export.py --device {device} --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]} "
|
74 |
+
+ "".join([f"--{x} " for x in tflite_options]))
|
75 |
+
else:
|
76 |
+
os.system(
|
77 |
+
f"python export.py --device {device} --imgsz {imgSize} --weights ./weights/{weight_name} --include {params_include_list[i]}"
|
78 |
+
)
|
79 |
e = time.time()
|
80 |
st.success(f"{params_include_list[i]}转换完成,用时{round((e-s), 2)}秒")
|
81 |
|
|
|
86 |
def main():
|
87 |
with st.container():
|
88 |
st.title("Streamlit YOLOv5 Model2X")
|
|
|
89 |
st.text("基于Streamlit的YOLOv5模型转换工具")
|
90 |
|
91 |
st.write("-------------------------------------------------------------")
|
|
|
106 |
fb.close()
|
107 |
st.success(f"{weight_name}写入成功!")
|
108 |
|
109 |
+
device = st.radio("请选择设备", ('cpu', 'cuda:0'), index=0)
|
110 |
+
imgSize = st.radio("请选择图片尺寸", (320, 640, 1280), index=1)
|
111 |
+
|
112 |
st.text("请选择转换的类型:")
|
113 |
cb_torchscript = st.checkbox('TorchScript')
|
114 |
+
|
115 |
+
# ------------- torchscript -------------
|
116 |
+
if cb_torchscript:
|
117 |
+
torchscript_options = st.multiselect('onnx选项', ['optimize'])
|
118 |
+
else:
|
119 |
+
torchscript_options = []
|
120 |
+
|
121 |
cb_onnx = st.checkbox('ONNX')
|
122 |
+
# ------------- onnx -------------
|
123 |
+
if cb_onnx:
|
124 |
+
onnx_options = st.multiselect('onnx选项', ['dynamic', 'simplify'])
|
125 |
+
else:
|
126 |
+
onnx_options = []
|
127 |
+
|
128 |
cb_openvino = st.checkbox('OpenVINO')
|
129 |
+
cb_engine = st.checkbox('TensorRT')
|
130 |
cb_coreml = st.checkbox('CoreML')
|
131 |
cb_saved_model = st.checkbox('TensorFlow SavedModel')
|
132 |
cb_pb = st.checkbox('TensorFlow GraphDef')
|
133 |
cb_tflite = st.checkbox('TensorFlow Lite')
|
134 |
+
|
135 |
+
# ------------- tflite -------------
|
136 |
+
if cb_tflite:
|
137 |
+
tflite_options = st.multiselect('tflite选项', ['int8', 'nms', 'agnostic-nms'])
|
138 |
+
else:
|
139 |
+
tflite_options = []
|
140 |
+
|
141 |
# cb_edgetpu = st.checkbox('TensorFlow Edge TPU')
|
142 |
cb_tfjs = st.checkbox('TensorFlow.js')
|
143 |
|
144 |
+
# ------------- tfjs -------------
|
145 |
+
if cb_tfjs:
|
146 |
+
iou_thres = st.slider(label='NMS IoU', min_value=0.0, max_value=1.0, value=0.45, step=0.05)
|
147 |
+
conf_thres = st.slider(label='NMS CONF', min_value=0.0, max_value=1.0, value=0.5, step=0.05)
|
148 |
+
else:
|
149 |
+
iou_thres, conf_thres = 0.45, 0.5
|
150 |
+
|
151 |
btn_convert = st.button('转换')
|
152 |
|
153 |
btn_model_list = [
|
154 |
+
cb_torchscript, cb_onnx, cb_openvino, cb_engine, cb_coreml, cb_saved_model, cb_pb, cb_tflite, cb_tfjs]
|
155 |
|
156 |
params_include_list = [
|
157 |
"torchscript", "onnx", "openvino", "engine", "coreml", "saved_model", "pb", "tflite", "tfjs"]
|
158 |
|
159 |
if btn_convert:
|
160 |
+
cb_opt(device, imgSize, weight_name, btn_model_list, params_include_list, [iou_thres, conf_thres],
|
161 |
+
tflite_options, onnx_options, torchscript_options)
|
162 |
|
163 |
st.write("-------------------------------------------------------------")
|
164 |
|