Spaces:
Runtime error
Runtime error
feat: ✨ Attempt ZeroGPU usage and NMS slider added
Browse filesSigned-off-by: Onuralp SEZER <[email protected]>
app.py
CHANGED
@@ -16,6 +16,7 @@ from torchvision.ops import nms
|
|
16 |
import supervision as sv
|
17 |
from PIL import Image
|
18 |
import cv2
|
|
|
19 |
|
20 |
import gradio as gr
|
21 |
|
@@ -31,7 +32,7 @@ Annototions Powered by [Supervision](https://github.com/roboflow/supervision).
|
|
31 |
|
32 |
EXAMPLES = [
|
33 |
["https://media.roboflow.com/efficient-sam/corgi.jpg", "dog",0.5,0.5,0.5,100],
|
34 |
-
["https://media.roboflow.com/efficient-sam/horses.jpg", "
|
35 |
["https://media.roboflow.com/efficient-sam/bears.jpg", "bear",0.5,0.5,0.5,100],
|
36 |
]
|
37 |
|
@@ -53,12 +54,13 @@ def load_runner():
|
|
53 |
runner.model.eval()
|
54 |
return runner
|
55 |
|
|
|
56 |
def run_image(
|
57 |
input_image,
|
58 |
class_names="person,car,bus,truck",
|
59 |
score_thr=0.05,
|
60 |
iou_thr=0.5,
|
61 |
-
nms_thr
|
62 |
max_num_boxes=100,
|
63 |
):
|
64 |
runner = load_runner()
|
@@ -137,11 +139,24 @@ iou_threshold_component = gr.Slider(
|
|
137 |
"detections."
|
138 |
))
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
with gr.Blocks() as demo:
|
141 |
gr.Markdown(TITLE)
|
142 |
with gr.Accordion("Configuration", open=False):
|
143 |
confidence_threshold_component.render()
|
144 |
iou_threshold_component.render()
|
|
|
145 |
with gr.Tab(label="Image"):
|
146 |
with gr.Row():
|
147 |
input_image_component = gr.Image(
|
@@ -171,6 +186,7 @@ with gr.Blocks() as demo:
|
|
171 |
image_categories_text_component,
|
172 |
confidence_threshold_component,
|
173 |
iou_threshold_component,
|
|
|
174 |
],
|
175 |
outputs=output_image_component
|
176 |
)
|
@@ -183,6 +199,7 @@ with gr.Blocks() as demo:
|
|
183 |
image_categories_text_component,
|
184 |
confidence_threshold_component,
|
185 |
iou_threshold_component,
|
|
|
186 |
],
|
187 |
outputs=output_image_component
|
188 |
)
|
|
|
16 |
import supervision as sv
|
17 |
from PIL import Image
|
18 |
import cv2
|
19 |
+
import spaces
|
20 |
|
21 |
import gradio as gr
|
22 |
|
|
|
32 |
|
33 |
EXAMPLES = [
|
34 |
["https://media.roboflow.com/efficient-sam/corgi.jpg", "dog",0.5,0.5,0.5,100],
|
35 |
+
["https://media.roboflow.com/efficient-sam/horses.jpg", "horses",0.5,0.5,0.5,100],
|
36 |
["https://media.roboflow.com/efficient-sam/bears.jpg", "bear",0.5,0.5,0.5,100],
|
37 |
]
|
38 |
|
|
|
54 |
runner.model.eval()
|
55 |
return runner
|
56 |
|
57 |
+
@spaces.GPU
|
58 |
def run_image(
|
59 |
input_image,
|
60 |
class_names="person,car,bus,truck",
|
61 |
score_thr=0.05,
|
62 |
iou_thr=0.5,
|
63 |
+
nms_thr=0.5,
|
64 |
max_num_boxes=100,
|
65 |
):
|
66 |
runner = load_runner()
|
|
|
139 |
"detections."
|
140 |
))
|
141 |
|
142 |
+
nms_threshold_component = gr.Slider(
|
143 |
+
minimum=0,
|
144 |
+
maximum=1.0,
|
145 |
+
value=0.5,
|
146 |
+
step=0.01,
|
147 |
+
label="NMS Threshold",
|
148 |
+
info=(
|
149 |
+
"The Non-Maximum Suppression (NMS) Threshold is a parameter that determines the Intersection over Union (IoU) threshold for suppressing bounding boxes. "
|
150 |
+
"A lower value will reduce the likelihood of overlapping bounding boxes, resulting in a more stringent detection process. Conversely, a higher value "
|
151 |
+
"will permit more overlapping bounding boxes, thereby allowing for a wider variety of detections."
|
152 |
+
))
|
153 |
+
|
154 |
with gr.Blocks() as demo:
|
155 |
gr.Markdown(TITLE)
|
156 |
with gr.Accordion("Configuration", open=False):
|
157 |
confidence_threshold_component.render()
|
158 |
iou_threshold_component.render()
|
159 |
+
nms_threshold_component.render()
|
160 |
with gr.Tab(label="Image"):
|
161 |
with gr.Row():
|
162 |
input_image_component = gr.Image(
|
|
|
186 |
image_categories_text_component,
|
187 |
confidence_threshold_component,
|
188 |
iou_threshold_component,
|
189 |
+
nms_threshold_component
|
190 |
],
|
191 |
outputs=output_image_component
|
192 |
)
|
|
|
199 |
image_categories_text_component,
|
200 |
confidence_threshold_component,
|
201 |
iou_threshold_component,
|
202 |
+
nms_threshold_component
|
203 |
],
|
204 |
outputs=output_image_component
|
205 |
)
|