Initial Commit
Browse files- README.md +2 -2
- app.py +161 -0
- examples/1.jpg +0 -0
- examples/2.jpg +0 -0
- examples/3.jpg +0 -0
- examples/4.jpg +0 -0
- examples/5.jpg +0 -0
- examples/6.jpg +0 -0
- models/yolo11m.pt +3 -0
- models/yolo11m_circuit_boards.pt +3 -0
- models/yolo11m_microscope_cells.pt +3 -0
- models/yolo11m_sign_language.pt +3 -0
- models/yolo11m_website_screenshots.pt +3 -0
- models/yolo11m_zoo_animals.pt +3 -0
- requirements.txt +8 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: YOLO Application Toolkit
|
3 |
emoji: π
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.1
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: YOLO Application Toolkit
|
3 |
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.44.1
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Tuple
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
import supervision as sv
|
5 |
+
from ultralytics import YOLO
|
6 |
+
import os
|
7 |
+
|
8 |
+
MARKDOWN = """
|
9 |
+
<h1 style='text-align: left'>YOLO Application Toolkit ππ</h1>
|
10 |
+
<p>Welcome to the YOLO Application Toolkit! This demo highlights the powerful detection capabilities of various YOLO models pre-trained on different datasets. π
|
11 |
+
|
12 |
+
Easily detect objects in images and videos on the go. Perfect for quick experimentation and practical use. ππ</p>
|
13 |
+
|
14 |
+
|
15 |
+
**YOLO11**
|
16 |
+
<div style="display: flex; align-items: center;">
|
17 |
+
<a href="https://docs.ultralytics.com/models/yolo11/" style="margin-right: 10px;">
|
18 |
+
<img src="https://badges.aleen42.com/src/github.svg">
|
19 |
+
</a>
|
20 |
+
<a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolo11-object-detection-on-custom-dataset.ipynb?ref=blog.roboflow.com" style="margin-right: 10px;">
|
21 |
+
<img src="https://colab.research.google.com/assets/colab-badge.svg">
|
22 |
+
</a>
|
23 |
+
</div>
|
24 |
+
|
25 |
+
Powered by Roboflow [Inference](https://github.com/roboflow/inference),
|
26 |
+
[Supervision](https://github.com/roboflow/supervision) and [Ultralytics](https://github.com/ultralytics/ultralytics).π₯
|
27 |
+
"""
|
28 |
+
|
29 |
+
MODEL_DIR = os.path.join(os.path.dirname(__file__), "models")
|
30 |
+
|
31 |
+
# Load models dynamically
|
32 |
+
MODELS = {
|
33 |
+
"YOLO11m (COCO128)": YOLO(os.path.join(MODEL_DIR, "yolo11m.pt")),
|
34 |
+
"American Sign Language (ASL) YOLO11m": YOLO(os.path.join(MODEL_DIR, "yolo11m_sign_language.pt")),
|
35 |
+
# "Microscopic Cell Detection YOLO11m": YOLO(os.path.join(MODEL_DIR, "yolo11m_microscope_cells.pt")),
|
36 |
+
"Website Screenshots YOLO11m": YOLO(os.path.join(MODEL_DIR, "yolo11m_website_screenshots.pt")),
|
37 |
+
"Zoo Animals YOLO11m": YOLO(os.path.join(MODEL_DIR, "yolo11m_zoo_animals.pt")),
|
38 |
+
"Pinned Circuit Boards YOLO11m": YOLO(os.path.join(MODEL_DIR, "yolo11m_circuit_boards.pt")),
|
39 |
+
}
|
40 |
+
|
41 |
+
example_dir = "https://huggingface.co/spaces/mbar0075/YOLO-Application-Toolkit/blob/main/"
|
42 |
+
# Your existing example dictionary
|
43 |
+
EXAMPLE_DICT = {
|
44 |
+
"YOLO11m (COCO128)": example_dir + "examples/1.jpg",
|
45 |
+
"American Sign Language (ASL) YOLO11m": example_dir + "examples/2.jpg",
|
46 |
+
# "Microscopic Cell Detection YOLO11m": example_dir + "examples/3.jpg",
|
47 |
+
"Website Screenshots YOLO11m": example_dir + "examples/4.jpg",
|
48 |
+
"Zoo Animals YOLO11m": example_dir + "examples/5.jpg",
|
49 |
+
"Pinned Circuit Boards YOLO11m": example_dir + "examples/6.jpg",
|
50 |
+
}
|
51 |
+
|
52 |
+
LABEL_ANNOTATORS = sv.LabelAnnotator()
|
53 |
+
BOUNDING_BOX_ANNOTATORS = sv.BoxAnnotator()
|
54 |
+
|
55 |
+
def detect_and_annotate(
|
56 |
+
model,
|
57 |
+
input_image: np.ndarray,
|
58 |
+
confidence_threshold: float,
|
59 |
+
iou_threshold: float,
|
60 |
+
class_id_mapping: dict = None
|
61 |
+
) -> np.ndarray:
|
62 |
+
result = model(input_image, conf=confidence_threshold, iou=iou_threshold)[0]
|
63 |
+
detections = sv.Detections.from_ultralytics(result)
|
64 |
+
|
65 |
+
if class_id_mapping:
|
66 |
+
detections.class_id = np.array([class_id_mapping[class_id] for class_id in detections.class_id])
|
67 |
+
|
68 |
+
labels = [f"{class_name} ({confidence:.2f})" for class_name, confidence in zip(detections['class_name'], detections.confidence)]
|
69 |
+
|
70 |
+
annotated_image = input_image.copy()
|
71 |
+
annotated_image = BOUNDING_BOX_ANNOTATORS.annotate(scene=annotated_image, detections=detections)
|
72 |
+
annotated_image = LABEL_ANNOTATORS.annotate(scene=annotated_image, detections=detections, labels=labels)
|
73 |
+
return annotated_image
|
74 |
+
|
75 |
+
def process_image(
|
76 |
+
input_image,
|
77 |
+
yolov11_confidence_threshold: float,
|
78 |
+
iou_threshold: float,
|
79 |
+
model_name: str
|
80 |
+
) -> np.ndarray:
|
81 |
+
# Load the selected model from the preloaded models
|
82 |
+
model = MODELS[model_name]
|
83 |
+
|
84 |
+
# Process the image
|
85 |
+
return detect_and_annotate(model, np.array(input_image), yolov11_confidence_threshold, iou_threshold)
|
86 |
+
|
87 |
+
# Gradio UI components
|
88 |
+
yolo_11s_confidence_threshold_component = gr.Slider(
|
89 |
+
minimum=0,
|
90 |
+
maximum=1.0,
|
91 |
+
value=0.3,
|
92 |
+
step=0.01,
|
93 |
+
label="YOLO11m Confidence Threshold",
|
94 |
+
info=(
|
95 |
+
"The confidence threshold for the YOLO model. Lower the threshold to "
|
96 |
+
"reduce false negatives, enhancing the model's sensitivity to detect "
|
97 |
+
"sought-after objects. Conversely, increase the threshold to minimize false "
|
98 |
+
"positives, preventing the model from identifying objects it shouldn't."
|
99 |
+
)
|
100 |
+
)
|
101 |
+
|
102 |
+
iou_threshold_component = gr.Slider(
|
103 |
+
minimum=0,
|
104 |
+
maximum=1.0,
|
105 |
+
value=0.5,
|
106 |
+
step=0.01,
|
107 |
+
label="IoU Threshold",
|
108 |
+
info=(
|
109 |
+
"The Intersection over Union (IoU) threshold for non-maximum suppression. "
|
110 |
+
"Decrease the value to lessen the occurrence of overlapping bounding boxes, "
|
111 |
+
"making the detection process stricter. On the other hand, increase the value "
|
112 |
+
"to allow more overlapping bounding boxes, accommodating a broader range of "
|
113 |
+
"detections."
|
114 |
+
)
|
115 |
+
)
|
116 |
+
|
117 |
+
model_dropdown = gr.Dropdown(
|
118 |
+
choices=list(MODELS.keys()),
|
119 |
+
label="Select Model",
|
120 |
+
value="YOLO11m (COCO128)",
|
121 |
+
info=(
|
122 |
+
"Choose the YOLO model you want to use for object detection. Each model is "
|
123 |
+
"trained on a specific dataset, making them suitable for various detection tasks."
|
124 |
+
)
|
125 |
+
)
|
126 |
+
|
127 |
+
def update_example(model_name):
|
128 |
+
return EXAMPLE_DICT[model_name]
|
129 |
+
|
130 |
+
with gr.Blocks() as demo:
|
131 |
+
gr.Markdown(MARKDOWN)
|
132 |
+
|
133 |
+
with gr.Accordion("Configuration", open=False):
|
134 |
+
yolo_11s_confidence_threshold_component.render()
|
135 |
+
iou_threshold_component.render()
|
136 |
+
|
137 |
+
with gr.Row():
|
138 |
+
model_dropdown.render()
|
139 |
+
|
140 |
+
with gr.Row():
|
141 |
+
image_input_component = gr.Image(type='pil', label='Input Image')
|
142 |
+
yolo_11s_output_component = gr.Image(type='pil', label='YOLO11s Output')
|
143 |
+
|
144 |
+
submit_button = gr.Button(value='Submit', scale=1, variant='primary')
|
145 |
+
|
146 |
+
gr.Examples(
|
147 |
+
fn=process_image,
|
148 |
+
examples=[[EXAMPLE_DICT[i], 0.3, 0.5, i] for i in EXAMPLE_DICT.keys()],
|
149 |
+
inputs=[image_input_component, yolo_11s_confidence_threshold_component, iou_threshold_component, model_dropdown],
|
150 |
+
outputs=[yolo_11s_output_component]
|
151 |
+
)
|
152 |
+
|
153 |
+
model_dropdown.change(fn=update_example, inputs=model_dropdown, outputs=image_input_component)
|
154 |
+
|
155 |
+
submit_button.click(
|
156 |
+
fn=process_image,
|
157 |
+
inputs=[image_input_component, yolo_11s_confidence_threshold_component, iou_threshold_component, model_dropdown],
|
158 |
+
outputs=[yolo_11s_output_component]
|
159 |
+
)
|
160 |
+
|
161 |
+
demo.launch(debug=False, show_error=True, max_threads=1)
|
examples/1.jpg
ADDED
![]() |
examples/2.jpg
ADDED
![]() |
examples/3.jpg
ADDED
![]() |
examples/4.jpg
ADDED
![]() |
examples/5.jpg
ADDED
![]() |
examples/6.jpg
ADDED
![]() |
models/yolo11m.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d5ffc1a674953a08e11a8d21e022781b1b23a19b730afc309290bd9fb5305b95
|
3 |
+
size 40684120
|
models/yolo11m_circuit_boards.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c417e1241d3f0fdcee4ed5fbc9432c489899f94cfd40e99e9f921e310e8a8f0c
|
3 |
+
size 40551845
|
models/yolo11m_microscope_cells.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:91180e565da11b9b152aa8dd459c6e003b6d67d9a23866be41d7c8c39c9aa2df
|
3 |
+
size 40514469
|
models/yolo11m_sign_language.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:016cdb005dee92fa77b5c6719800a94cecadeb14c87fcec8047c9848f99e4425
|
3 |
+
size 40569189
|
models/yolo11m_website_screenshots.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0d1529998c0bc22bde5dd30ff87370aac6d389f636fa0d97ee18514ec38f82dc
|
3 |
+
size 40516261
|
models/yolo11m_zoo_animals.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:54d77afc923f0e3a5c0d5170105d0c453e06aa4ba8367171ed7e84a6b37b0422
|
3 |
+
size 40534629
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
setuptools<70.0.0
|
2 |
+
awscli==1.29.54
|
3 |
+
gradio
|
4 |
+
inference
|
5 |
+
supervision
|
6 |
+
ultralytics
|
7 |
+
dill
|
8 |
+
timm
|