Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
YOLOv10 added
Browse files
README.md
CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
|
|
7 |
sdk_version: 4.19.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
7 |
sdk_version: 4.19.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -6,7 +6,14 @@ import supervision as sv
|
|
6 |
from inference import get_model
|
7 |
|
8 |
MARKDOWN = """
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
Powered by Roboflow [Inference](https://github.com/roboflow/inference) and
|
12 |
[Supervision](https://github.com/roboflow/supervision).
|
@@ -16,77 +23,55 @@ IMAGE_EXAMPLES = [
|
|
16 |
['https://media.roboflow.com/dog.jpeg', 0.3]
|
17 |
]
|
18 |
|
19 |
-
YOLO_V8_MODEL = get_model(model_id="
|
20 |
-
YOLO_NAS_MODEL = get_model(model_id="coco/
|
21 |
YOLO_V9_MODEL = get_model(model_id="coco/17")
|
|
|
22 |
|
23 |
LABEL_ANNOTATORS = sv.LabelAnnotator(text_color=sv.Color.black())
|
24 |
BOUNDING_BOX_ANNOTATORS = sv.BoundingBoxAnnotator()
|
25 |
|
26 |
|
27 |
-
def
|
|
|
28 |
input_image: np.ndarray,
|
29 |
confidence_threshold: float,
|
30 |
iou_threshold: float
|
31 |
-
) ->
|
32 |
-
|
33 |
-
input_image,
|
34 |
-
confidence=confidence_threshold,
|
35 |
-
iou_threshold=iou_threshold
|
36 |
-
)[0]
|
37 |
-
yolo_v8_detections = sv.Detections.from_inference(yolo_v8_result)
|
38 |
-
|
39 |
-
labels = [
|
40 |
-
f"{class_name} {confidence:.2f}"
|
41 |
-
for class_name, confidence
|
42 |
-
in zip(yolo_v8_detections["class_name"], yolo_v8_detections.confidence)
|
43 |
-
]
|
44 |
-
|
45 |
-
yolo_v8_annotated_image = input_image.copy()
|
46 |
-
yolo_v8_annotated_image = BOUNDING_BOX_ANNOTATORS.annotate(
|
47 |
-
scene=yolo_v8_annotated_image, detections=yolo_v8_detections)
|
48 |
-
yolo_v8_annotated_image = LABEL_ANNOTATORS.annotate(
|
49 |
-
scene=yolo_v8_annotated_image, detections=yolo_v8_detections, labels=labels)
|
50 |
-
|
51 |
-
yolo_nas_result = YOLO_NAS_MODEL.infer(
|
52 |
-
input_image,
|
53 |
-
confidence=confidence_threshold,
|
54 |
-
iou_threshold=iou_threshold
|
55 |
-
)[0]
|
56 |
-
yolo_nas_detections = sv.Detections.from_inference(yolo_nas_result)
|
57 |
-
|
58 |
-
labels = [
|
59 |
-
f"{class_name} {confidence:.2f}"
|
60 |
-
for class_name, confidence
|
61 |
-
in zip(yolo_nas_detections["class_name"], yolo_nas_detections.confidence)
|
62 |
-
]
|
63 |
-
|
64 |
-
yolo_nas_annotated_image = input_image.copy()
|
65 |
-
yolo_nas_annotated_image = BOUNDING_BOX_ANNOTATORS.annotate(
|
66 |
-
scene=yolo_nas_annotated_image, detections=yolo_nas_detections)
|
67 |
-
yolo_nas_annotated_image = LABEL_ANNOTATORS.annotate(
|
68 |
-
scene=yolo_nas_annotated_image, detections=yolo_nas_detections, labels=labels)
|
69 |
-
|
70 |
-
yolo_v9_result = YOLO_V9_MODEL.infer(
|
71 |
input_image,
|
72 |
confidence=confidence_threshold,
|
73 |
iou_threshold=iou_threshold
|
74 |
)[0]
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
labels = [
|
78 |
-
f"{class_name} {confidence:.2f}"
|
79 |
-
for class_name, confidence
|
80 |
-
in zip(yolo_v9_detections["class_name"], yolo_v9_detections.confidence)
|
81 |
-
]
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
|
92 |
confidence_threshold_component = gr.Slider(
|
@@ -125,21 +110,27 @@ with gr.Blocks() as demo:
|
|
125 |
with gr.Row():
|
126 |
input_image_component = gr.Image(
|
127 |
type='numpy',
|
128 |
-
label='Input
|
129 |
-
)
|
130 |
-
yolo_v8_output_image_component = gr.Image(
|
131 |
-
type='numpy',
|
132 |
-
label='YOLOv8 Output'
|
133 |
-
)
|
134 |
-
with gr.Row():
|
135 |
-
yolo_nas_output_image_component = gr.Image(
|
136 |
-
type='numpy',
|
137 |
-
label='YOLO-NAS Output'
|
138 |
-
)
|
139 |
-
yolo_v9_output_image_component = gr.Image(
|
140 |
-
type='numpy',
|
141 |
-
label='YOLOv9 Output'
|
142 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
submit_button_component = gr.Button(
|
144 |
value='Submit',
|
145 |
scale=1,
|
@@ -156,7 +147,8 @@ with gr.Blocks() as demo:
|
|
156 |
outputs=[
|
157 |
yolo_v8_output_image_component,
|
158 |
yolo_nas_output_image_component,
|
159 |
-
yolo_v9_output_image_component
|
|
|
160 |
]
|
161 |
)
|
162 |
|
@@ -170,7 +162,8 @@ with gr.Blocks() as demo:
|
|
170 |
outputs=[
|
171 |
yolo_v8_output_image_component,
|
172 |
yolo_nas_output_image_component,
|
173 |
-
yolo_v9_output_image_component
|
|
|
174 |
]
|
175 |
)
|
176 |
|
|
|
6 |
from inference import get_model
|
7 |
|
8 |
MARKDOWN = """
|
9 |
+
<h1 style='text-align: center'>YOLO-ARENA 🏟️</h1>
|
10 |
+
|
11 |
+
Welcome to YOLO-Arena! This demo showcases the performance of various YOLO models:
|
12 |
+
|
13 |
+
- YOLOv8
|
14 |
+
- YOLOv9
|
15 |
+
- YOLOv10
|
16 |
+
- YOLO-NAS
|
17 |
|
18 |
Powered by Roboflow [Inference](https://github.com/roboflow/inference) and
|
19 |
[Supervision](https://github.com/roboflow/supervision).
|
|
|
23 |
['https://media.roboflow.com/dog.jpeg', 0.3]
|
24 |
]
|
25 |
|
26 |
+
YOLO_V8_MODEL = get_model(model_id="yolov8m-640")
|
27 |
+
YOLO_NAS_MODEL = get_model(model_id="coco/15")
|
28 |
YOLO_V9_MODEL = get_model(model_id="coco/17")
|
29 |
+
YOLO_V10_MODEL = get_model(model_id="coco/22")
|
30 |
|
31 |
LABEL_ANNOTATORS = sv.LabelAnnotator(text_color=sv.Color.black())
|
32 |
BOUNDING_BOX_ANNOTATORS = sv.BoundingBoxAnnotator()
|
33 |
|
34 |
|
35 |
+
def detect_and_annotate(
|
36 |
+
model,
|
37 |
input_image: np.ndarray,
|
38 |
confidence_threshold: float,
|
39 |
iou_threshold: float
|
40 |
+
) -> np.ndarray:
|
41 |
+
result = model.infer(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
input_image,
|
43 |
confidence=confidence_threshold,
|
44 |
iou_threshold=iou_threshold
|
45 |
)[0]
|
46 |
+
detections = sv.Detections.from_inference(result)
|
47 |
+
annotated_image = input_image.copy()
|
48 |
+
annotated_image = BOUNDING_BOX_ANNOTATORS.annotate(
|
49 |
+
scene=annotated_image, detections=detections)
|
50 |
+
annotated_image = LABEL_ANNOTATORS.annotate(
|
51 |
+
scene=annotated_image, detections=detections)
|
52 |
+
return annotated_image
|
53 |
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
def process_image(
|
56 |
+
input_image: np.ndarray,
|
57 |
+
confidence_threshold: float,
|
58 |
+
iou_threshold: float
|
59 |
+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
|
60 |
+
yolo_v8_annotated_image = detect_and_annotate(
|
61 |
+
YOLO_V8_MODEL, input_image, confidence_threshold, iou_threshold)
|
62 |
+
yolo_nas_annotated_image = detect_and_annotate(
|
63 |
+
YOLO_NAS_MODEL, input_image, confidence_threshold, iou_threshold)
|
64 |
+
yolo_v9_annotated_image = detect_and_annotate(
|
65 |
+
YOLO_V9_MODEL, input_image, confidence_threshold, iou_threshold)
|
66 |
+
yolo_10_annotated_image = detect_and_annotate(
|
67 |
+
YOLO_V10_MODEL, input_image, confidence_threshold, iou_threshold)
|
68 |
+
|
69 |
+
return (
|
70 |
+
yolo_v8_annotated_image,
|
71 |
+
yolo_nas_annotated_image,
|
72 |
+
yolo_v9_annotated_image,
|
73 |
+
yolo_10_annotated_image
|
74 |
+
)
|
75 |
|
76 |
|
77 |
confidence_threshold_component = gr.Slider(
|
|
|
110 |
with gr.Row():
|
111 |
input_image_component = gr.Image(
|
112 |
type='numpy',
|
113 |
+
label='Input'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
)
|
115 |
+
with gr.Column():
|
116 |
+
with gr.Row():
|
117 |
+
yolo_v8_output_image_component = gr.Image(
|
118 |
+
type='numpy',
|
119 |
+
label='YOLOv8m @ 640x640'
|
120 |
+
)
|
121 |
+
yolo_nas_output_image_component = gr.Image(
|
122 |
+
type='numpy',
|
123 |
+
label='YOLO-NAS M @ 640x640'
|
124 |
+
)
|
125 |
+
with gr.Row():
|
126 |
+
yolo_v9_output_image_component = gr.Image(
|
127 |
+
type='numpy',
|
128 |
+
label='YOLOv9c @ 640x640'
|
129 |
+
)
|
130 |
+
yolo_v10_output_image_component = gr.Image(
|
131 |
+
type='numpy',
|
132 |
+
label='YOLOv10m @ 640x640'
|
133 |
+
)
|
134 |
submit_button_component = gr.Button(
|
135 |
value='Submit',
|
136 |
scale=1,
|
|
|
147 |
outputs=[
|
148 |
yolo_v8_output_image_component,
|
149 |
yolo_nas_output_image_component,
|
150 |
+
yolo_v9_output_image_component,
|
151 |
+
yolo_v10_output_image_component
|
152 |
]
|
153 |
)
|
154 |
|
|
|
162 |
outputs=[
|
163 |
yolo_v8_output_image_component,
|
164 |
yolo_nas_output_image_component,
|
165 |
+
yolo_v9_output_image_component,
|
166 |
+
yolo_v10_output_image_component
|
167 |
]
|
168 |
)
|
169 |
|