ninja990621 commited on
Commit
4701ccd
·
verified ·
1 Parent(s): e4b0527

scorevision: push artifact

Browse files
Files changed (1) hide show
  1. miner.py +19 -1
miner.py CHANGED
@@ -18,10 +18,14 @@ from pydantic import BaseModel
18
  NUM_CLASSES = 5
19
  DEFAULT_INPUT_SIZE = 640
20
  # Per-class score thresholds, tuned offline with Score's own per-image scorer.
21
- CONF_THRESHOLDS = (0.25, 0.25, 0.25, 0.25, 0.25)
22
  NMS_IOU = 0.5
23
  # Score's answer key gives each object one class: drop a weaker box of another class sitting on the same spot.
24
  CROSS_CLASS_IOU = 2
 
 
 
 
25
  MAX_DETECTIONS = 30
26
  PAD_VALUE = 114
27
 
@@ -64,6 +68,14 @@ def box_iou(a: ndarray, b: ndarray) -> float:
64
  return float(inter / union) if union > 0 else 0.0
65
 
66
 
 
 
 
 
 
 
 
 
67
  def nms(boxes: ndarray, scores: ndarray, iou_threshold: float) -> list[int]:
68
  x1, y1, x2, y2 = boxes.T
69
  areas = (x2 - x1).clip(0) * (y2 - y1).clip(0)
@@ -130,6 +142,12 @@ class Miner:
130
  if all(kc == c or box_iou(b, kb) < CROSS_CLASS_IOU for kb, kc, _ in kept):
131
  kept.append((b, c, sc))
132
  results = kept
 
 
 
 
 
 
133
  return [(int(round(b[0])), int(round(b[1])), int(round(b[2])), int(round(b[3])), c, s)
134
  for b, c, s in results[:MAX_DETECTIONS] if b[2] - b[0] >= 1 and b[3] - b[1] >= 1]
135
 
 
18
  NUM_CLASSES = 5
19
  DEFAULT_INPUT_SIZE = 640
20
  # Per-class score thresholds, tuned offline with Score's own per-image scorer.
21
+ CONF_THRESHOLDS = (0.25, 0.25, 0.25, 0.25, 0.35)
22
  NMS_IOU = 0.5
23
  # Score's answer key gives each object one class: drop a weaker box of another class sitting on the same spot.
24
  CROSS_CLASS_IOU = 2
25
+ # Score's labeller gives one box per object and drops a mask lying inside a bigger mask of the same prompt, so a
26
+ # same-class box mostly inside a bigger, about as confident box is a piece of that object (e.g. one item of a pile).
27
+ INSIDE_SHARE = 0.7
28
+ INSIDE_CONF_RATIO = 0.9
29
  MAX_DETECTIONS = 30
30
  PAD_VALUE = 114
31
 
 
68
  return float(inter / union) if union > 0 else 0.0
69
 
70
 
71
+ def inside_share(a: ndarray, b: ndarray) -> float:
72
+ """Share of the smaller box's area covered by the other box."""
73
+ iw = max(0.0, min(a[2], b[2]) - max(a[0], b[0]))
74
+ ih = max(0.0, min(a[3], b[3]) - max(a[1], b[1]))
75
+ smaller = min((a[2] - a[0]) * (a[3] - a[1]), (b[2] - b[0]) * (b[3] - b[1]))
76
+ return float(iw * ih / smaller) if smaller > 0 else 0.0
77
+
78
+
79
  def nms(boxes: ndarray, scores: ndarray, iou_threshold: float) -> list[int]:
80
  x1, y1, x2, y2 = boxes.T
81
  areas = (x2 - x1).clip(0) * (y2 - y1).clip(0)
 
142
  if all(kc == c or box_iou(b, kb) < CROSS_CLASS_IOU for kb, kc, _ in kept):
143
  kept.append((b, c, sc))
144
  results = kept
145
+ kept = []
146
+ for b, c, sc in sorted(results, key=lambda t: -(t[0][2] - t[0][0]) * (t[0][3] - t[0][1])):
147
+ if not any(kc == c and ks >= INSIDE_CONF_RATIO * sc and inside_share(b, kb) >= INSIDE_SHARE
148
+ for kb, kc, ks in kept):
149
+ kept.append((b, c, sc))
150
+ results = sorted(kept, key=lambda t: -t[2])
151
  return [(int(round(b[0])), int(round(b[1])), int(round(b[2])), int(round(b[3])), c, s)
152
  for b, c, s in results[:MAX_DETECTIONS] if b[2] - b[0] >= 1 and b[3] - b[1] >= 1]
153