Spaces:
Runtime error
Runtime error
Xu Ma
commited on
Commit
•
041c78a
1
Parent(s):
ae140ff
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,3 @@
|
|
1 |
-
# Gradio YOLOv5 Det v0.1
|
2 |
-
# 创建人:曾逸夫
|
3 |
-
# 创建时间:2022-04-03
|
4 |
-
# email:[email protected]
|
5 |
-
# 项目主页:https://gitee.com/CV_Lab/gradio_yolov5_det
|
6 |
-
|
7 |
import argparse
|
8 |
import csv
|
9 |
import sys
|
@@ -18,20 +12,14 @@ ROOT_PATH = sys.path[0] # 根目录
|
|
18 |
|
19 |
# 模型路径
|
20 |
model_path = "ultralytics/yolov5"
|
21 |
-
|
22 |
-
|
23 |
# 模型名称临时变量
|
24 |
model_name_tmp = ""
|
25 |
-
|
26 |
# 设备临时变量
|
27 |
device_tmp = ""
|
28 |
-
|
29 |
# 文件后缀
|
30 |
suffix_list = [".csv", ".yaml"]
|
31 |
-
|
32 |
-
|
33 |
def parse_args(known=False):
|
34 |
-
parser = argparse.ArgumentParser(description="Gradio
|
35 |
parser.add_argument(
|
36 |
"--model_name", "-mn", default="yolov5s", type=str, help="model name"
|
37 |
)
|
@@ -80,8 +68,6 @@ def parse_args(known=False):
|
|
80 |
|
81 |
args = parser.parse_known_args()[0] if known else parser.parse_args()
|
82 |
return args
|
83 |
-
|
84 |
-
|
85 |
# 模型加载
|
86 |
def model_loading(model_name, device):
|
87 |
|
@@ -89,8 +75,6 @@ def model_loading(model_name, device):
|
|
89 |
model = torch.hub.load(model_path, model_name, force_reload=True, device=device)
|
90 |
|
91 |
return model
|
92 |
-
|
93 |
-
|
94 |
# 检测信息
|
95 |
def export_json(results, model, img_size):
|
96 |
|
@@ -115,8 +99,6 @@ def export_json(results, model, img_size):
|
|
115 |
]
|
116 |
for result in results.xyxyn
|
117 |
]
|
118 |
-
|
119 |
-
|
120 |
def yolo_det(img, experiment_id, device=None, model_name=None, inference_size=None, conf=None, iou=None, label_opt=None, model_cls=None):
|
121 |
|
122 |
global model, model_name_tmp, device_tmp
|
@@ -145,6 +127,13 @@ def yolo_det(img, experiment_id, device=None, model_name=None, inference_size=No
|
|
145 |
return det_img, det_json
|
146 |
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
# yaml文件解析
|
149 |
def yaml_parse(file_path):
|
150 |
return yaml.safe_load(open(file_path, "r", encoding="utf-8").read())
|
@@ -193,8 +182,8 @@ def main(args):
|
|
193 |
inputs_img = gr.inputs.Image(type="pil", label="Input Image")
|
194 |
experiment_id = gr.inputs.Radio(
|
195 |
choices=[
|
196 |
-
"add [1,1,1,1,1] total 5 paths",
|
197 |
-
"add [1,1,1,1,1,1,1,1] total 8 paths",
|
198 |
"add [1,2,4,8,16,32, ...] total 128 paths",
|
199 |
"add [1,2,4,8,16,32, ...] total 256 paths"], type="value", default="add [1,1,1,1,1] paths", label="Path Adding Scheduler"
|
200 |
)
|
@@ -248,11 +237,11 @@ def main(args):
|
|
248 |
examples = [
|
249 |
[
|
250 |
"./examples/1.png",
|
251 |
-
"add [1,1,1,1,1] total 5 paths",
|
252 |
],
|
253 |
[
|
254 |
"./examples/2.png",
|
255 |
-
"add [1,1,1,1,1] total 5 paths",
|
256 |
],
|
257 |
[
|
258 |
"./examples/3.jpg",
|
@@ -264,7 +253,7 @@ def main(args):
|
|
264 |
],
|
265 |
[
|
266 |
"./examples/5.png",
|
267 |
-
"add [1,1,1,1,1] total 5 paths",
|
268 |
],
|
269 |
]
|
270 |
|
@@ -274,7 +263,7 @@ def main(args):
|
|
274 |
inputs=inputs,
|
275 |
outputs=[outputs, outputs02],
|
276 |
title=title,
|
277 |
-
|
278 |
examples=examples,
|
279 |
theme="seafoam",
|
280 |
# live=True, # 实时变更输出
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import argparse
|
2 |
import csv
|
3 |
import sys
|
|
|
12 |
|
13 |
# 模型路径
|
14 |
model_path = "ultralytics/yolov5"
|
|
|
|
|
15 |
# 模型名称临时变量
|
16 |
model_name_tmp = ""
|
|
|
17 |
# 设备临时变量
|
18 |
device_tmp = ""
|
|
|
19 |
# 文件后缀
|
20 |
suffix_list = [".csv", ".yaml"]
|
|
|
|
|
21 |
def parse_args(known=False):
|
22 |
+
parser = argparse.ArgumentParser(description="Gradio LIVE")
|
23 |
parser.add_argument(
|
24 |
"--model_name", "-mn", default="yolov5s", type=str, help="model name"
|
25 |
)
|
|
|
68 |
|
69 |
args = parser.parse_known_args()[0] if known else parser.parse_args()
|
70 |
return args
|
|
|
|
|
71 |
# 模型加载
|
72 |
def model_loading(model_name, device):
|
73 |
|
|
|
75 |
model = torch.hub.load(model_path, model_name, force_reload=True, device=device)
|
76 |
|
77 |
return model
|
|
|
|
|
78 |
# 检测信息
|
79 |
def export_json(results, model, img_size):
|
80 |
|
|
|
99 |
]
|
100 |
for result in results.xyxyn
|
101 |
]
|
|
|
|
|
102 |
def yolo_det(img, experiment_id, device=None, model_name=None, inference_size=None, conf=None, iou=None, label_opt=None, model_cls=None):
|
103 |
|
104 |
global model, model_name_tmp, device_tmp
|
|
|
127 |
return det_img, det_json
|
128 |
|
129 |
|
130 |
+
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
# yaml文件解析
|
138 |
def yaml_parse(file_path):
|
139 |
return yaml.safe_load(open(file_path, "r", encoding="utf-8").read())
|
|
|
182 |
inputs_img = gr.inputs.Image(type="pil", label="Input Image")
|
183 |
experiment_id = gr.inputs.Radio(
|
184 |
choices=[
|
185 |
+
"add [1, 1, 1, 1, 1] total 5 paths",
|
186 |
+
"add [1, 1, 1, 1, 1, 1, 1, 1] total 8 paths",
|
187 |
"add [1,2,4,8,16,32, ...] total 128 paths",
|
188 |
"add [1,2,4,8,16,32, ...] total 256 paths"], type="value", default="add [1,1,1,1,1] paths", label="Path Adding Scheduler"
|
189 |
)
|
|
|
237 |
examples = [
|
238 |
[
|
239 |
"./examples/1.png",
|
240 |
+
"add [1, 1, 1, 1, 1] total 5 paths",
|
241 |
],
|
242 |
[
|
243 |
"./examples/2.png",
|
244 |
+
"add [1, 1, 1, 1, 1] total 5 paths",
|
245 |
],
|
246 |
[
|
247 |
"./examples/3.jpg",
|
|
|
253 |
],
|
254 |
[
|
255 |
"./examples/5.png",
|
256 |
+
"add [1, 1, 1, 1, 1] total 5 paths",
|
257 |
],
|
258 |
]
|
259 |
|
|
|
263 |
inputs=inputs,
|
264 |
outputs=[outputs, outputs02],
|
265 |
title=title,
|
266 |
+
description=description,
|
267 |
examples=examples,
|
268 |
theme="seafoam",
|
269 |
# live=True, # 实时变更输出
|