Spaces:
Running
Running
Orkhan Hasanli commited on
Commit ·
89db832
1
Parent(s): b915b77
Added person crop threshold 0.9
Browse files- app.py +11 -1
- dfine_jina_pipeline.py +5 -3
app.py
CHANGED
|
@@ -253,14 +253,24 @@ with gr.Blocks(title="Small Object Detection") as app:
|
|
| 253 |
label="D-FINE model",
|
| 254 |
)
|
| 255 |
|
|
|
|
| 256 |
dfine_threshold_slider = gr.Slider(
|
| 257 |
minimum=0.05,
|
| 258 |
maximum=0.5,
|
| 259 |
-
value=0.
|
| 260 |
step=0.05,
|
| 261 |
label="D-FINE detection threshold (applied to chosen model)",
|
| 262 |
)
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
refs_path = gr.Textbox(
|
| 265 |
label="Refs folder path",
|
| 266 |
value=REFS_DIR,
|
|
|
|
| 253 |
label="D-FINE model",
|
| 254 |
)
|
| 255 |
|
| 256 |
+
# Default threshold: Large=0.2, Medium=0.15 (slider updates when model changes)
|
| 257 |
dfine_threshold_slider = gr.Slider(
|
| 258 |
minimum=0.05,
|
| 259 |
maximum=0.5,
|
| 260 |
+
value=0.2,
|
| 261 |
step=0.05,
|
| 262 |
label="D-FINE detection threshold (applied to chosen model)",
|
| 263 |
)
|
| 264 |
|
| 265 |
+
def update_dfine_threshold_default(choice):
|
| 266 |
+
return gr.update(value=0.2 if (choice and choice.strip().lower() == "large") else 0.15)
|
| 267 |
+
|
| 268 |
+
dfine_model_radio.change(
|
| 269 |
+
fn=update_dfine_threshold_default,
|
| 270 |
+
inputs=[dfine_model_radio],
|
| 271 |
+
outputs=[dfine_threshold_slider],
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
refs_path = gr.Textbox(
|
| 275 |
label="Refs folder path",
|
| 276 |
value=REFS_DIR,
|
dfine_jina_pipeline.py
CHANGED
|
@@ -29,6 +29,8 @@ from jina_fewshot import (
|
|
| 29 |
KNOWN_DISPLAY_CLASSES = {"gun", "knife", "cigarette", "phone"}
|
| 30 |
# Only show objects (and group crops) with confidence >= this
|
| 31 |
MIN_DISPLAY_CONF = 0.7
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# -----------------------------------------------------------------------------
|
| 34 |
# Detection + grouping (from reference_detection.py)
|
|
@@ -342,7 +344,7 @@ def main():
|
|
| 342 |
args.det_threshold
|
| 343 |
)
|
| 344 |
|
| 345 |
-
person_car = [d for d in detections if d["cls"] in person_car_ids]
|
| 346 |
if not person_car:
|
| 347 |
continue
|
| 348 |
|
|
@@ -539,9 +541,9 @@ def run_single_image(
|
|
| 539 |
|
| 540 |
# Apply user's D-FINE detection threshold to the chosen model (medium or large)
|
| 541 |
detections = run_dfine(pil, image_processor, dfine_model_obj, device, det_threshold)
|
| 542 |
-
person_car = [d for d in detections if d["cls"] in person_car_ids]
|
| 543 |
if not person_car:
|
| 544 |
-
return [], [], "No person/car detected. No small-object crops."
|
| 545 |
|
| 546 |
grouped = group_detections(person_car, group_dist)
|
| 547 |
grouped.sort(key=lambda x: x["conf"], reverse=True)
|
|
|
|
| 29 |
KNOWN_DISPLAY_CLASSES = {"gun", "knife", "cigarette", "phone"}
|
| 30 |
# Only show objects (and group crops) with confidence >= this
|
| 31 |
MIN_DISPLAY_CONF = 0.7
|
| 32 |
+
# Person/car detections must have confidence > this to be used for grouping
|
| 33 |
+
PERSON_CAR_MIN_CONF = 0.9
|
| 34 |
|
| 35 |
# -----------------------------------------------------------------------------
|
| 36 |
# Detection + grouping (from reference_detection.py)
|
|
|
|
| 344 |
args.det_threshold
|
| 345 |
)
|
| 346 |
|
| 347 |
+
person_car = [d for d in detections if d["cls"] in person_car_ids and d["conf"] > PERSON_CAR_MIN_CONF]
|
| 348 |
if not person_car:
|
| 349 |
continue
|
| 350 |
|
|
|
|
| 541 |
|
| 542 |
# Apply user's D-FINE detection threshold to the chosen model (medium or large)
|
| 543 |
detections = run_dfine(pil, image_processor, dfine_model_obj, device, det_threshold)
|
| 544 |
+
person_car = [d for d in detections if d["cls"] in person_car_ids and d["conf"] > PERSON_CAR_MIN_CONF]
|
| 545 |
if not person_car:
|
| 546 |
+
return [], [], "No person/car detected (or none with confidence > 0.9). No small-object crops."
|
| 547 |
|
| 548 |
grouped = group_detections(person_car, group_dist)
|
| 549 |
grouped.sort(key=lambda x: x["conf"], reverse=True)
|