Spaces:
Sleeping
Sleeping
Added YOLO11
Browse files- README.md +1 -1
- app.py +120 -49
- requirements.txt +6 -3
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
|
|
1 |
---
|
2 |
+
title: YOLO-Playground
|
3 |
emoji: π
|
4 |
colorFrom: blue
|
5 |
colorTo: green
|
app.py
CHANGED
@@ -3,32 +3,76 @@ from typing import Tuple
|
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import supervision as sv
|
6 |
-
from
|
7 |
|
8 |
MARKDOWN = """
|
9 |
-
<h1 style='text-align:
|
10 |
-
Welcome to
|
11 |
|
12 |
A simple project just for fun for on the go object detection. π
|
13 |
|
14 |
Inspired from YOLO-ARENA by SkalskiP. π
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
|
20 |
IMAGE_EXAMPLES = [
|
21 |
-
['https://media.roboflow.com/supervision/image-examples/people-walking.png', 0.3, 0.3, 0.3],
|
22 |
-
['https://media.roboflow.com/supervision/image-examples/vehicles.png', 0.3, 0.3, 0.3],
|
23 |
-
['https://media.roboflow.com/supervision/image-examples/basketball-1.png', 0.3, 0.3, 0.3],
|
24 |
]
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
LABEL_ANNOTATORS = sv.LabelAnnotator(
|
31 |
-
BOUNDING_BOX_ANNOTATORS = sv.
|
32 |
|
33 |
|
34 |
def detect_and_annotate(
|
@@ -38,12 +82,12 @@ def detect_and_annotate(
|
|
38 |
iou_threshold: float,
|
39 |
class_id_mapping: dict = None
|
40 |
) -> np.ndarray:
|
41 |
-
result = model
|
42 |
input_image,
|
43 |
-
|
44 |
-
|
45 |
)[0]
|
46 |
-
detections = sv.Detections.
|
47 |
|
48 |
if class_id_mapping:
|
49 |
detections.class_id = np.array([
|
@@ -71,32 +115,49 @@ def process_image(
|
|
71 |
yolo_v8_confidence_threshold: float,
|
72 |
yolo_v9_confidence_threshold: float,
|
73 |
yolo_v10_confidence_threshold: float,
|
|
|
74 |
iou_threshold: float
|
75 |
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
|
76 |
# Validate iou_threshold before using it
|
77 |
if iou_threshold is None or not isinstance(iou_threshold, float):
|
78 |
iou_threshold = 0.3 # Default value, adjust as necessary
|
79 |
|
80 |
-
yolo_v8n_annotated_image = detect_and_annotate(
|
81 |
-
YOLO_V8N_MODEL, input_image, yolo_v8_confidence_threshold, iou_threshold)
|
82 |
yolo_v8s_annotated_image = detect_and_annotate(
|
83 |
-
YOLO_V8S_MODEL, input_image,
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
|
87 |
return (
|
88 |
-
yolo_v8n_annotated_image,
|
89 |
yolo_v8s_annotated_image,
|
90 |
-
|
|
|
|
|
91 |
)
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
|
|
|
95 |
minimum=0,
|
96 |
maximum=1.0,
|
97 |
value=0.3,
|
98 |
step=0.01,
|
99 |
-
label="
|
100 |
info=(
|
101 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
102 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
@@ -104,12 +165,12 @@ yolo_v8N_confidence_threshold_component = gr.Slider(
|
|
104 |
"positives, preventing the model from identifying objects it shouldn't."
|
105 |
))
|
106 |
|
107 |
-
|
108 |
minimum=0,
|
109 |
maximum=1.0,
|
110 |
value=0.3,
|
111 |
step=0.01,
|
112 |
-
label="
|
113 |
info=(
|
114 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
115 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
@@ -117,12 +178,12 @@ yolo_v8S_confidence_threshold_component = gr.Slider(
|
|
117 |
"positives, preventing the model from identifying objects it shouldn't."
|
118 |
))
|
119 |
|
120 |
-
|
121 |
minimum=0,
|
122 |
maximum=1.0,
|
123 |
value=0.3,
|
124 |
step=0.01,
|
125 |
-
label="
|
126 |
info=(
|
127 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
128 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
@@ -149,27 +210,33 @@ with gr.Blocks() as demo:
|
|
149 |
gr.Markdown(MARKDOWN)
|
150 |
with gr.Accordion("Configuration", open=False):
|
151 |
with gr.Row():
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
155 |
iou_threshold_component.render()
|
156 |
with gr.Row():
|
157 |
input_image_component = gr.Image(
|
158 |
type='pil',
|
159 |
label='Input'
|
160 |
)
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
162 |
type='pil',
|
163 |
-
label='
|
164 |
)
|
165 |
with gr.Row():
|
166 |
-
|
167 |
type='pil',
|
168 |
-
label='
|
169 |
)
|
170 |
-
|
171 |
type='pil',
|
172 |
-
label='
|
173 |
)
|
174 |
submit_button_component = gr.Button(
|
175 |
value='Submit',
|
@@ -181,15 +248,17 @@ with gr.Blocks() as demo:
|
|
181 |
examples=IMAGE_EXAMPLES,
|
182 |
inputs=[
|
183 |
input_image_component,
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
187 |
iou_threshold_component
|
188 |
],
|
189 |
outputs=[
|
190 |
-
yolo_v8n_output_image_component,
|
191 |
yolo_v8s_output_image_component,
|
192 |
-
|
|
|
|
|
193 |
]
|
194 |
)
|
195 |
|
@@ -197,15 +266,17 @@ with gr.Blocks() as demo:
|
|
197 |
fn=process_image,
|
198 |
inputs=[
|
199 |
input_image_component,
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
203 |
iou_threshold_component
|
204 |
],
|
205 |
outputs=[
|
206 |
-
yolo_v8n_output_image_component,
|
207 |
yolo_v8s_output_image_component,
|
208 |
-
|
|
|
|
|
209 |
]
|
210 |
)
|
211 |
|
|
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import supervision as sv
|
6 |
+
from ultralytics import YOLO
|
7 |
|
8 |
MARKDOWN = """
|
9 |
+
<h1 style='text-align: left'>YOLO-Playground π</h1>
|
10 |
+
Welcome to YOLO-Playground! This demo showcases the detection capabilities of various YOLO models pre-trained on the COCO Dataset. πππ
|
11 |
|
12 |
A simple project just for fun for on the go object detection. π
|
13 |
|
14 |
Inspired from YOLO-ARENA by SkalskiP. π
|
15 |
|
16 |
+
- **YOLOv8**
|
17 |
+
<div style="display: flex; align-items: center;">
|
18 |
+
<a href="https://docs.ultralytics.com/models/yolov8/" style="margin-right: 10px;">
|
19 |
+
<img src="https://badges.aleen42.com/src/github.svg">
|
20 |
+
</a>
|
21 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov8-object-detection-on-custom-dataset.ipynb" style="margin-right: 10px;">
|
22 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg">
|
23 |
+
</a>
|
24 |
+
</div>
|
25 |
+
- **YOLOv9**
|
26 |
+
<div style="display: flex; align-items: center;">
|
27 |
+
<a href="https://github.com/WongKinYiu/yolov9" style="margin-right: 10px;">
|
28 |
+
<img src="https://badges.aleen42.com/src/github.svg">
|
29 |
+
</a>
|
30 |
+
<a href="https://arxiv.org/abs/2402.13616" style="margin-right: 10px;">
|
31 |
+
<img src="https://img.shields.io/badge/arXiv-2402.13616-b31b1b.svg">
|
32 |
+
</a>
|
33 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov9-object-detection-on-custom-dataset.ipynb" style="margin-right: 10px;">
|
34 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg">
|
35 |
+
</a>
|
36 |
+
</div>
|
37 |
+
- **YOLOv10**
|
38 |
+
<div style="display: flex; align-items: center;">
|
39 |
+
<a href="https://github.com/THU-MIG/yolov10" style="margin-right: 10px;">
|
40 |
+
<img src="https://badges.aleen42.com/src/github.svg">
|
41 |
+
</a>
|
42 |
+
<a href="https://arxiv.org/abs/2405.14458" style="margin-right: 10px;">
|
43 |
+
<img src="https://img.shields.io/badge/arXiv-2405.14458-b31b1b.svg">
|
44 |
+
</a>
|
45 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov10-object-detection-on-custom-dataset.ipynb" style="margin-right: 10px;">
|
46 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg">
|
47 |
+
</a>
|
48 |
+
</div>
|
49 |
+
- **YOLO11**
|
50 |
+
<div style="display: flex; align-items: center;">
|
51 |
+
<a href="https://docs.ultralytics.com/models/yolo11/" style="margin-right: 10px;">
|
52 |
+
<img src="https://badges.aleen42.com/src/github.svg">
|
53 |
+
</a>
|
54 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov8-object-detection-on-custom-dataset.ipynb" style="margin-right: 10px;">
|
55 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg">
|
56 |
+
</a>
|
57 |
+
</div>
|
58 |
+
|
59 |
+
Powered by Roboflow [Inference](https://github.com/roboflow/inference),
|
60 |
+
[Supervision](https://github.com/roboflow/supervision) and [Ultralytics](https://github.com/ultralytics/ultralytics).π₯
|
61 |
"""
|
62 |
|
63 |
IMAGE_EXAMPLES = [
|
64 |
+
['https://media.roboflow.com/supervision/image-examples/people-walking.png', 0.3, 0.3, 0.3, 0.3, 0.5],
|
65 |
+
['https://media.roboflow.com/supervision/image-examples/vehicles.png', 0.3, 0.3, 0.3, 0.3, 0.5],
|
66 |
+
['https://media.roboflow.com/supervision/image-examples/basketball-1.png', 0.3, 0.3, 0.3, 0.3, 0.5],
|
67 |
]
|
68 |
|
69 |
+
YOLO_V8S_MODEL = YOLO("yolov8s.pt")
|
70 |
+
YOLO_V9S_MODEL = YOLO("yolov9s.pt")
|
71 |
+
YOLO_V10S_MODEL = YOLO("yolov10s.pt")
|
72 |
+
YOLO_11S_MODEL = YOLO("yolo11s.pt")
|
73 |
|
74 |
+
LABEL_ANNOTATORS = sv.LabelAnnotator()
|
75 |
+
BOUNDING_BOX_ANNOTATORS = sv.BoxAnnotator()
|
76 |
|
77 |
|
78 |
def detect_and_annotate(
|
|
|
82 |
iou_threshold: float,
|
83 |
class_id_mapping: dict = None
|
84 |
) -> np.ndarray:
|
85 |
+
result = model(
|
86 |
input_image,
|
87 |
+
conf=confidence_threshold,
|
88 |
+
iou=iou_threshold
|
89 |
)[0]
|
90 |
+
detections = sv.Detections.from_ultralytics(result)
|
91 |
|
92 |
if class_id_mapping:
|
93 |
detections.class_id = np.array([
|
|
|
115 |
yolo_v8_confidence_threshold: float,
|
116 |
yolo_v9_confidence_threshold: float,
|
117 |
yolo_v10_confidence_threshold: float,
|
118 |
+
yolov11_confidence_threshold: float,
|
119 |
iou_threshold: float
|
120 |
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
|
121 |
# Validate iou_threshold before using it
|
122 |
if iou_threshold is None or not isinstance(iou_threshold, float):
|
123 |
iou_threshold = 0.3 # Default value, adjust as necessary
|
124 |
|
|
|
|
|
125 |
yolo_v8s_annotated_image = detect_and_annotate(
|
126 |
+
YOLO_V8S_MODEL, input_image, yolo_v8_confidence_threshold, iou_threshold)
|
127 |
+
yolo_v9s_annotated_image = detect_and_annotate(
|
128 |
+
YOLO_V9S_MODEL, input_image, yolo_v9_confidence_threshold, iou_threshold)
|
129 |
+
yolo_v10s_annotated_image = detect_and_annotate(
|
130 |
+
YOLO_V10S_MODEL, input_image, yolo_v10_confidence_threshold, iou_threshold)
|
131 |
+
yolo_11s_annnotated_image = detect_and_annotate(
|
132 |
+
YOLO_11S_MODEL, input_image, yolov11_confidence_threshold, iou_threshold)
|
133 |
|
134 |
return (
|
|
|
135 |
yolo_v8s_annotated_image,
|
136 |
+
yolo_v9s_annotated_image,
|
137 |
+
yolo_v10s_annotated_image,
|
138 |
+
yolo_11s_annnotated_image
|
139 |
)
|
140 |
|
141 |
+
yolo_v8s_confidence_threshold_component = gr.Slider(
|
142 |
+
minimum=0,
|
143 |
+
maximum=1.0,
|
144 |
+
value=0.3,
|
145 |
+
step=0.01,
|
146 |
+
label="YOLOv8s Confidence Threshold",
|
147 |
+
info=(
|
148 |
+
"The confidence threshold for the YOLO model. Lower the threshold to "
|
149 |
+
"reduce false negatives, enhancing the model's sensitivity to detect "
|
150 |
+
"sought-after objects. Conversely, increase the threshold to minimize false "
|
151 |
+
"positives, preventing the model from identifying objects it shouldn't."
|
152 |
+
))
|
153 |
|
154 |
+
|
155 |
+
yolo_v9s_confidence_threshold_component = gr.Slider(
|
156 |
minimum=0,
|
157 |
maximum=1.0,
|
158 |
value=0.3,
|
159 |
step=0.01,
|
160 |
+
label="YOLOv9s Confidence Threshold",
|
161 |
info=(
|
162 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
163 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
|
|
165 |
"positives, preventing the model from identifying objects it shouldn't."
|
166 |
))
|
167 |
|
168 |
+
yolo_v10s_confidence_threshold_component = gr.Slider(
|
169 |
minimum=0,
|
170 |
maximum=1.0,
|
171 |
value=0.3,
|
172 |
step=0.01,
|
173 |
+
label="YOLOv10s Confidence Threshold",
|
174 |
info=(
|
175 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
176 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
|
|
178 |
"positives, preventing the model from identifying objects it shouldn't."
|
179 |
))
|
180 |
|
181 |
+
yolo_11s_confidence_threshold_component = gr.Slider(
|
182 |
minimum=0,
|
183 |
maximum=1.0,
|
184 |
value=0.3,
|
185 |
step=0.01,
|
186 |
+
label="YOLO11s Confidence Threshold",
|
187 |
info=(
|
188 |
"The confidence threshold for the YOLO model. Lower the threshold to "
|
189 |
"reduce false negatives, enhancing the model's sensitivity to detect "
|
|
|
210 |
gr.Markdown(MARKDOWN)
|
211 |
with gr.Accordion("Configuration", open=False):
|
212 |
with gr.Row():
|
213 |
+
yolo_v8s_confidence_threshold_component.render()
|
214 |
+
yolo_v9s_confidence_threshold_component.render()
|
215 |
+
yolo_v10s_confidence_threshold_component.render()
|
216 |
+
yolo_11s_confidence_threshold_component.render()
|
217 |
iou_threshold_component.render()
|
218 |
with gr.Row():
|
219 |
input_image_component = gr.Image(
|
220 |
type='pil',
|
221 |
label='Input'
|
222 |
)
|
223 |
+
with gr.Row():
|
224 |
+
yolo_v8s_output_image_component = gr.Image(
|
225 |
+
type='pil',
|
226 |
+
label='YOLOv8s'
|
227 |
+
)
|
228 |
+
yolo_v9s_output_image_component = gr.Image(
|
229 |
type='pil',
|
230 |
+
label='YOLOv9s'
|
231 |
)
|
232 |
with gr.Row():
|
233 |
+
yolo_v10s_output_image_component = gr.Image(
|
234 |
type='pil',
|
235 |
+
label='YOLOv10s'
|
236 |
)
|
237 |
+
yolo_11s_output_image_component = gr.Image(
|
238 |
type='pil',
|
239 |
+
label='YOLO11s'
|
240 |
)
|
241 |
submit_button_component = gr.Button(
|
242 |
value='Submit',
|
|
|
248 |
examples=IMAGE_EXAMPLES,
|
249 |
inputs=[
|
250 |
input_image_component,
|
251 |
+
yolo_v8s_confidence_threshold_component,
|
252 |
+
yolo_v9s_confidence_threshold_component,
|
253 |
+
yolo_v10s_confidence_threshold_component,
|
254 |
+
yolo_11s_confidence_threshold_component,
|
255 |
iou_threshold_component
|
256 |
],
|
257 |
outputs=[
|
|
|
258 |
yolo_v8s_output_image_component,
|
259 |
+
yolo_v9s_output_image_component,
|
260 |
+
yolo_v10s_output_image_component,
|
261 |
+
yolo_11s_output_image_component
|
262 |
]
|
263 |
)
|
264 |
|
|
|
266 |
fn=process_image,
|
267 |
inputs=[
|
268 |
input_image_component,
|
269 |
+
yolo_v8s_confidence_threshold_component,
|
270 |
+
yolo_v9s_confidence_threshold_component,
|
271 |
+
yolo_v10s_confidence_threshold_component,
|
272 |
+
yolo_11s_confidence_threshold_component,
|
273 |
iou_threshold_component
|
274 |
],
|
275 |
outputs=[
|
|
|
276 |
yolo_v8s_output_image_component,
|
277 |
+
yolo_v9s_output_image_component,
|
278 |
+
yolo_v10s_output_image_component,
|
279 |
+
yolo_11s_output_image_component
|
280 |
]
|
281 |
)
|
282 |
|
requirements.txt
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
setuptools<70.0.0
|
2 |
awscli==1.29.54
|
3 |
-
gradio
|
4 |
-
inference
|
5 |
-
supervision
|
|
|
|
|
|
|
|
1 |
setuptools<70.0.0
|
2 |
awscli==1.29.54
|
3 |
+
gradio
|
4 |
+
inference
|
5 |
+
supervision
|
6 |
+
ultralytics
|
7 |
+
pill
|
8 |
+
timm
|