Orkhan Hasanli commited on
Commit
bf32d2c
·
1 Parent(s): be400de

D-FINE: show only groups with known objects, display conf >= 0.7

Browse files
Files changed (1) hide show
  1. dfine_jina_pipeline.py +10 -6
dfine_jina_pipeline.py CHANGED
@@ -27,6 +27,8 @@ from jina_fewshot import (
27
 
28
  # Only these ref classes get bboxes on group crops and appear in the known-object gallery
29
  KNOWN_DISPLAY_CLASSES = {"gun", "knife", "cigarette", "phone"}
 
 
30
 
31
  from nomic_fewshot import NomicTextEncoder, NomicVisionEncoder, build_refs_nomic
32
 
@@ -686,7 +688,7 @@ def run_single_image(
686
  conf = result["confidence"]
687
  results_per_crop.append((gidx, (bx1, by1, bx2, by2), crop_pil, pred, conf))
688
 
689
- # Build group crop images: one per person/car group, with bboxes only for known objects
690
  group_crop_images = []
691
  for gidx, grp in enumerate(top_groups):
692
  gx1, gy1, gx2, gy2 = grp["box"]
@@ -701,7 +703,7 @@ def run_single_image(
701
 
702
  boxes_to_draw = []
703
  for (gidx2, (bx1, by1, bx2, by2), _crop_pil, pred, conf) in results_per_crop:
704
- if gidx2 != gidx or pred not in KNOWN_DISPLAY_CLASSES:
705
  continue
706
  # Convert to group-crop-relative coords and clamp
707
  rx1 = max(0, min(crop_w, bx1 - gx1))
@@ -711,14 +713,16 @@ def run_single_image(
711
  if rx2 > rx1 and ry2 > ry1:
712
  boxes_to_draw.append((rx1, ry1, rx2, ry2, pred, conf))
713
 
714
- if boxes_to_draw:
715
- group_crop = draw_bboxes_on_image(group_crop, boxes_to_draw)
 
 
716
  group_crop_images.append(np.array(group_crop))
717
 
718
- # Build known-only gallery: composite (label above + crop) for each accepted known class
719
  known_crop_composites = []
720
  for (_gidx, _box, crop_pil, pred, conf) in results_per_crop:
721
- if pred not in KNOWN_DISPLAY_CLASSES:
722
  continue
723
  composite = draw_label_on_image(crop_pil, pred, conf)
724
  known_crop_composites.append(np.array(composite))
 
27
 
28
  # Only these ref classes get bboxes on group crops and appear in the known-object gallery
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
  from nomic_fewshot import NomicTextEncoder, NomicVisionEncoder, build_refs_nomic
34
 
 
688
  conf = result["confidence"]
689
  results_per_crop.append((gidx, (bx1, by1, bx2, by2), crop_pil, pred, conf))
690
 
691
+ # Build group crop images: only groups that contain at least one known object with conf >= MIN_DISPLAY_CONF
692
  group_crop_images = []
693
  for gidx, grp in enumerate(top_groups):
694
  gx1, gy1, gx2, gy2 = grp["box"]
 
703
 
704
  boxes_to_draw = []
705
  for (gidx2, (bx1, by1, bx2, by2), _crop_pil, pred, conf) in results_per_crop:
706
+ if gidx2 != gidx or pred not in KNOWN_DISPLAY_CLASSES or conf < MIN_DISPLAY_CONF:
707
  continue
708
  # Convert to group-crop-relative coords and clamp
709
  rx1 = max(0, min(crop_w, bx1 - gx1))
 
713
  if rx2 > rx1 and ry2 > ry1:
714
  boxes_to_draw.append((rx1, ry1, rx2, ry2, pred, conf))
715
 
716
+ # Only show this group crop if it has at least one known object >= MIN_DISPLAY_CONF
717
+ if not boxes_to_draw:
718
+ continue
719
+ group_crop = draw_bboxes_on_image(group_crop, boxes_to_draw)
720
  group_crop_images.append(np.array(group_crop))
721
 
722
+ # Build known-only gallery: only objects with conf >= MIN_DISPLAY_CONF
723
  known_crop_composites = []
724
  for (_gidx, _box, crop_pil, pred, conf) in results_per_crop:
725
+ if pred not in KNOWN_DISPLAY_CLASSES or conf < MIN_DISPLAY_CONF:
726
  continue
727
  composite = draw_label_on_image(crop_pil, pred, conf)
728
  known_crop_composites.append(np.array(composite))