Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,10 @@ def load_model(model_name):
|
|
16 |
model_path = "yolov9c.pt"
|
17 |
elif model_name == "yolov9e":
|
18 |
model_path = "yolov9e.pt"
|
|
|
|
|
|
|
|
|
19 |
else:
|
20 |
raise ValueError(f"Invalid model name: {model_name}")
|
21 |
|
@@ -26,12 +30,12 @@ def predict_image(img, conf_threshold, iou_threshold, task="detection", model_na
|
|
26 |
if task == "segmentation":
|
27 |
if not model_name:
|
28 |
model_name = "yolov9c-seg"
|
29 |
-
elif model_name not in ["yolov9c-seg", "yolov9e-seg"]:
|
30 |
raise ValueError(f"Invalid model name for segmentation: {model_name}")
|
31 |
elif task == "detection":
|
32 |
if not model_name:
|
33 |
model_name = "yolov9c"
|
34 |
-
elif model_name not in ["yolov9c", "yolov9e"]:
|
35 |
raise ValueError(f"Invalid model name for detection: {model_name}")
|
36 |
else:
|
37 |
raise ValueError(f"Invalid task: {task}. Choose either 'segmentation' or 'detection'.")
|
@@ -63,13 +67,14 @@ image_iface = gr.Interface(
|
|
63 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
64 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
65 |
gr.Dropdown(choices=["detection", "segmentation"], value="detection", label="Task"),
|
66 |
-
gr.Dropdown(choices=["yolov9c", "yolov9e", "yolov9c-seg", "yolov9e-seg"], value="yolov9c", label="Model"),
|
67 |
],
|
68 |
outputs=gr.Image(type="pil", label="Result"),
|
69 |
title="X509",
|
70 |
description="Upload images for inference. Choose task and corresponding model.",
|
71 |
examples=[
|
72 |
["cars.jpg", 0.25, 0.45, "detection", "yolov9c"],
|
|
|
73 |
],
|
74 |
)
|
75 |
|
@@ -78,12 +83,12 @@ def predict_video(video_path, conf_threshold, iou_threshold, task="detection", m
|
|
78 |
if task == "segmentation":
|
79 |
if not model_name:
|
80 |
model_name = "yolov9c-seg"
|
81 |
-
elif model_name not in ["yolov9c-seg", "yolov9e-seg"]:
|
82 |
raise ValueError(f"Invalid model name for segmentation: {model_name}")
|
83 |
elif task == "detection":
|
84 |
if not model_name:
|
85 |
model_name = "yolov9c"
|
86 |
-
elif model_name not in ["yolov9c", "yolov9e"]:
|
87 |
raise ValueError(f"Invalid model name for detection: {model_name}")
|
88 |
else:
|
89 |
raise ValueError(f"Invalid task: {task}. Choose either 'segmentation' or 'detection'.")
|
@@ -146,13 +151,14 @@ video_iface = gr.Interface(
|
|
146 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
147 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
148 |
gr.Dropdown(choices=["detection", "segmentation"], value="detection", label="Task"),
|
149 |
-
gr.Dropdown(choices=["yolov9c", "yolov9e", "yolov9c-seg", "yolov9e-seg"], value="yolov9c", label="Model"),
|
150 |
],
|
151 |
outputs=gr.File(label="Result"),
|
152 |
title="X509",
|
153 |
description="Upload video for inference. Choose task and corresponding model.",
|
154 |
examples=[
|
155 |
-
["VID_20240517112011.mp4", 0.25, 0.45, "detection", "
|
|
|
156 |
]
|
157 |
)
|
158 |
|
|
|
16 |
model_path = "yolov9c.pt"
|
17 |
elif model_name == "yolov9e":
|
18 |
model_path = "yolov9e.pt"
|
19 |
+
elif model_name == "yolov8n":
|
20 |
+
model_path = "yolov8n.pt"
|
21 |
+
elif model_name == "yolov8n-seg":
|
22 |
+
model_path = "yolov8n-seg.pt"
|
23 |
else:
|
24 |
raise ValueError(f"Invalid model name: {model_name}")
|
25 |
|
|
|
30 |
if task == "segmentation":
|
31 |
if not model_name:
|
32 |
model_name = "yolov9c-seg"
|
33 |
+
elif model_name not in ["yolov9c-seg", "yolov9e-seg", "yolov8n-seg"]:
|
34 |
raise ValueError(f"Invalid model name for segmentation: {model_name}")
|
35 |
elif task == "detection":
|
36 |
if not model_name:
|
37 |
model_name = "yolov9c"
|
38 |
+
elif model_name not in ["yolov9c", "yolov9e", "yolov8n"]:
|
39 |
raise ValueError(f"Invalid model name for detection: {model_name}")
|
40 |
else:
|
41 |
raise ValueError(f"Invalid task: {task}. Choose either 'segmentation' or 'detection'.")
|
|
|
67 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
68 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
69 |
gr.Dropdown(choices=["detection", "segmentation"], value="detection", label="Task"),
|
70 |
+
gr.Dropdown(choices=["yolov9c", "yolov9e", "yolov8n", "yolov9c-seg", "yolov9e-seg", "yolov8n-seg"], value="yolov9c", label="Model"),
|
71 |
],
|
72 |
outputs=gr.Image(type="pil", label="Result"),
|
73 |
title="X509",
|
74 |
description="Upload images for inference. Choose task and corresponding model.",
|
75 |
examples=[
|
76 |
["cars.jpg", 0.25, 0.45, "detection", "yolov9c"],
|
77 |
+
["cars.jpg", 0.25, 0.45, "segmentation", "yolov9c-seg"],
|
78 |
],
|
79 |
)
|
80 |
|
|
|
83 |
if task == "segmentation":
|
84 |
if not model_name:
|
85 |
model_name = "yolov9c-seg"
|
86 |
+
elif model_name not in ["yolov9c-seg", "yolov9e-seg", "yolov8n-seg"]:
|
87 |
raise ValueError(f"Invalid model name for segmentation: {model_name}")
|
88 |
elif task == "detection":
|
89 |
if not model_name:
|
90 |
model_name = "yolov9c"
|
91 |
+
elif model_name not in ["yolov9c", "yolov9e", "yolov8n"]:
|
92 |
raise ValueError(f"Invalid model name for detection: {model_name}")
|
93 |
else:
|
94 |
raise ValueError(f"Invalid task: {task}. Choose either 'segmentation' or 'detection'.")
|
|
|
151 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
152 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
153 |
gr.Dropdown(choices=["detection", "segmentation"], value="detection", label="Task"),
|
154 |
+
gr.Dropdown(choices=["yolov9c", "yolov9e", "yolov8n", "yolov9c-seg", "yolov9e-seg", "yolov8n-seg"], value="yolov9c", label="Model"),
|
155 |
],
|
156 |
outputs=gr.File(label="Result"),
|
157 |
title="X509",
|
158 |
description="Upload video for inference. Choose task and corresponding model.",
|
159 |
examples=[
|
160 |
+
["VID_20240517112011.mp4", 0.25, 0.45, "detection", "yolov8n"],
|
161 |
+
["VID_20240517112011.mp4", 0.25, 0.45, "segmentation", "yolov8n-seg"],
|
162 |
]
|
163 |
)
|
164 |
|