coolroman commited on
Commit
6e32d36
·
verified ·
1 Parent(s): 212bbe0

scorevision: push artifact

Browse files
Files changed (1) hide show
  1. miner.py +32 -1
miner.py CHANGED
@@ -368,6 +368,36 @@ class Miner:
368
  kept.append(box)
369
  return kept
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  @classmethod
372
  def _apply_rules(cls, results, image_width, image=None):
373
  results = cls._filter_glove_by_color(results, image)
@@ -375,7 +405,8 @@ class Miner:
375
  results = cls._filter_weak_glove_with_strong_others(results)
376
  results = cls._filter_split_glove_confidence(results)
377
  results = cls._filter_crowded_gloves(results)
378
- return cls._filter_orphan_low_conf_spray(results)
 
379
 
380
  def _predict_single(self, image):
381
  x, ratio, pad, orig_size = self._preprocess(image)
 
368
  kept.append(box)
369
  return kept
370
 
371
+ @classmethod
372
+ def _box_iou_pair(cls, a, b):
373
+ inter = cls._box_intersection_area(a, b)
374
+ aw = max(0.0, float(a.x2 - a.x1)) * max(0.0, float(a.y2 - a.y1))
375
+ bw = max(0.0, float(b.x2 - b.x1)) * max(0.0, float(b.y2 - b.y1))
376
+ union = aw + bw - inter
377
+ if union <= 0: return 0.0
378
+ return inter / union
379
+
380
+ @classmethod
381
+ def _aggressive_dedup_balaclava_graffiti(cls, results, iou_thr=0.10):
382
+ """For balaclava (cls 0) and graffiti (cls 5), drop lower-conf box
383
+ whenever any two boxes of the same class overlap > iou_thr.
384
+ Rationale: one face = one balaclava; one tag = one graffiti box."""
385
+ target = {0, 5}
386
+ others = [b for b in results if b.cls_id not in target]
387
+ by_cls = {}
388
+ for b in results:
389
+ if b.cls_id in target:
390
+ by_cls.setdefault(b.cls_id, []).append(b)
391
+ kept = list(others)
392
+ for cid, boxes in by_cls.items():
393
+ boxes_sorted = sorted(boxes, key=lambda b: -b.conf)
394
+ survivors = []
395
+ for b in boxes_sorted:
396
+ if all(cls._box_iou_pair(b, k) < iou_thr for k in survivors):
397
+ survivors.append(b)
398
+ kept.extend(survivors)
399
+ return kept
400
+
401
  @classmethod
402
  def _apply_rules(cls, results, image_width, image=None):
403
  results = cls._filter_glove_by_color(results, image)
 
405
  results = cls._filter_weak_glove_with_strong_others(results)
406
  results = cls._filter_split_glove_confidence(results)
407
  results = cls._filter_crowded_gloves(results)
408
+ results = cls._filter_orphan_low_conf_spray(results)
409
+ return cls._aggressive_dedup_balaclava_graffiti(results)
410
 
411
  def _predict_single(self, image):
412
  x, ratio, pad, orig_size = self._preprocess(image)