Spaces:
Running
Running
Orkhan Hasanli commited on
Commit ·
f851934
1
Parent(s): 89db832
Added gap value to the interface
Browse files
app.py
CHANGED
|
@@ -108,7 +108,7 @@ def run_detection(image, model):
|
|
| 108 |
return out_img, det_json
|
| 109 |
|
| 110 |
|
| 111 |
-
def run_dfine_classify(image, refs_path, dfine_threshold, dfine_model_choice, min_display_conf=0.
|
| 112 |
"""Tab 2: D-FINE first, then classify crops with Jina.
|
| 113 |
Returns (group_crop_gallery, known_crop_gallery, status_message).
|
| 114 |
"""
|
|
@@ -120,8 +120,6 @@ def run_dfine_classify(image, refs_path, dfine_threshold, dfine_model_choice, mi
|
|
| 120 |
if not refs.is_dir():
|
| 121 |
return [], [], f"Refs folder not found: {refs}"
|
| 122 |
|
| 123 |
-
# Tuned on COCO GT: conf=0.5, gap=0.02.
|
| 124 |
-
# Lower det_threshold/min_side so D-FINE picks up more objects (gun, phone, etc.) like local.
|
| 125 |
dfine_model = "large" if dfine_model_choice.strip().lower() == "large" else "medium"
|
| 126 |
group_crops, known_crops, status = run_single_image(
|
| 127 |
image,
|
|
@@ -129,7 +127,7 @@ def run_dfine_classify(image, refs_path, dfine_threshold, dfine_model_choice, mi
|
|
| 129 |
dfine_model=dfine_model,
|
| 130 |
det_threshold=float(dfine_threshold),
|
| 131 |
conf_threshold=0.5,
|
| 132 |
-
gap_threshold=
|
| 133 |
min_side=24,
|
| 134 |
crop_dedup_iou=0.4,
|
| 135 |
min_display_conf=float(min_display_conf),
|
|
@@ -287,11 +285,19 @@ with gr.Blocks(title="Small Object Detection") as app:
|
|
| 287 |
threshold_slider = gr.Slider(
|
| 288 |
minimum=0.0,
|
| 289 |
maximum=1.0,
|
| 290 |
-
value=0.
|
| 291 |
-
step=0.
|
| 292 |
label="Threshold (min display confidence)",
|
| 293 |
)
|
| 294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
out_gallery_dfine = gr.Gallery(
|
| 296 |
label="Person/car crops (all D-FINE objects inside drawn with label + score)",
|
| 297 |
height=IMG_HEIGHT,
|
|
@@ -314,7 +320,7 @@ with gr.Blocks(title="Small Object Detection") as app:
|
|
| 314 |
|
| 315 |
btn_dfine.click(
|
| 316 |
fn=run_dfine_classify,
|
| 317 |
-
inputs=[inp_dfine, refs_path, dfine_threshold_slider, dfine_model_radio, threshold_slider],
|
| 318 |
outputs=[out_gallery_dfine, out_gallery_known, out_status_dfine],
|
| 319 |
concurrency_limit=1,
|
| 320 |
)
|
|
|
|
| 108 |
return out_img, det_json
|
| 109 |
|
| 110 |
|
| 111 |
+
def run_dfine_classify(image, refs_path, dfine_threshold, dfine_model_choice, min_display_conf=0.705, gap_threshold=0.02):
|
| 112 |
"""Tab 2: D-FINE first, then classify crops with Jina.
|
| 113 |
Returns (group_crop_gallery, known_crop_gallery, status_message).
|
| 114 |
"""
|
|
|
|
| 120 |
if not refs.is_dir():
|
| 121 |
return [], [], f"Refs folder not found: {refs}"
|
| 122 |
|
|
|
|
|
|
|
| 123 |
dfine_model = "large" if dfine_model_choice.strip().lower() == "large" else "medium"
|
| 124 |
group_crops, known_crops, status = run_single_image(
|
| 125 |
image,
|
|
|
|
| 127 |
dfine_model=dfine_model,
|
| 128 |
det_threshold=float(dfine_threshold),
|
| 129 |
conf_threshold=0.5,
|
| 130 |
+
gap_threshold=float(gap_threshold),
|
| 131 |
min_side=24,
|
| 132 |
crop_dedup_iou=0.4,
|
| 133 |
min_display_conf=float(min_display_conf),
|
|
|
|
| 285 |
threshold_slider = gr.Slider(
|
| 286 |
minimum=0.0,
|
| 287 |
maximum=1.0,
|
| 288 |
+
value=0.705,
|
| 289 |
+
step=0.005,
|
| 290 |
label="Threshold (min display confidence)",
|
| 291 |
)
|
| 292 |
|
| 293 |
+
gap_slider = gr.Slider(
|
| 294 |
+
minimum=0.0,
|
| 295 |
+
maximum=0.02,
|
| 296 |
+
value=0.02,
|
| 297 |
+
step=0.001,
|
| 298 |
+
label="Gap threshold (best − second-best; accept class only if gap ≥ this)",
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
out_gallery_dfine = gr.Gallery(
|
| 302 |
label="Person/car crops (all D-FINE objects inside drawn with label + score)",
|
| 303 |
height=IMG_HEIGHT,
|
|
|
|
| 320 |
|
| 321 |
btn_dfine.click(
|
| 322 |
fn=run_dfine_classify,
|
| 323 |
+
inputs=[inp_dfine, refs_path, dfine_threshold_slider, dfine_model_radio, threshold_slider, gap_slider],
|
| 324 |
outputs=[out_gallery_dfine, out_gallery_known, out_status_dfine],
|
| 325 |
concurrency_limit=1,
|
| 326 |
)
|