Duy commited on
Commit
46c5997
·
1 Parent(s): 7d835bb

Remove borderline DINOv2 rescue — detection at (928,731) was FP on wire corner

Browse files

The hybrid Chamfer(3.0-3.7)+DINOv2≥0.88 rescue introduced in the previous
session caught a wire-corner T-junction as a false R9 detection. The wire
corner's DINOv2 embedding (0.913) happened to be close to the resistor
template, but visually it is clearly not a resistor. Strict Chamfer≤3.0
already captures all 9 circuit resistors cleanly; the 10th apparent detection
was noise.

Back to 9 clean detections (drawing 1). All 10 unit tests pass.

Files changed (1) hide show
  1. src/pipeline.py +4 -28
src/pipeline.py CHANGED
@@ -150,31 +150,12 @@ class PatternDetectionPipeline:
150
  # unreliable for binary line-art and rejects correctly-detected vertical
151
  # components (R2/R4/R6/R8 score < 0.84 despite being real resistors).
152
  if cands_s:
153
- # Strict chamfer pre-filter (≤3.0) — catches most components.
154
- # Borderline range (3.0–3.7): run DINOv2 to rescue high-confidence
155
- # real components whose drawing region has adjacent noise edges
156
- # pushing their Chamfer score just above 3.0 (dino≥0.86 required).
157
- _cands_with_ch = self.postprocessor.filter_chamfer_shape(
158
- cands_s, drawing_proc, pattern_proc, max_chamfer=3.7
159
  )
160
- cands_strict = [c for c in _cands_with_ch if c.get("chamfer_dist", 0) <= 3.0]
161
- cands_borderline = [c for c in _cands_with_ch if c.get("chamfer_dist", 0) > 3.0]
162
- if cands_borderline:
163
- _bl_saved_thr = self.dino_verifier.cosine_threshold
164
- self.dino_verifier.cosine_threshold = 0.0
165
- bl_scored = self.dino_verifier.verify_candidates(
166
- drawing_proc, pattern_proc, cands_borderline, derotate=False
167
- )
168
- self.dino_verifier.cosine_threshold = _bl_saved_thr
169
- cands_borderline = [c for c in bl_scored if c.get("dino_score", 0) >= 0.88]
170
- else:
171
- cands_borderline = []
172
- for c in cands_strict:
173
  c.setdefault("dino_score", 0.0)
174
  c.setdefault("confidence", c.get("ncc_score", 0.5))
175
- for c in cands_borderline:
176
- c.setdefault("confidence", (c.get("ncc_score", 0.5) + c.get("dino_score", 0)) / 2)
177
- cands_s = cands_strict + cands_borderline
178
  before_s = len(cands_s)
179
  cands_s = self.postprocessor.filter_title_block(cands_s, drawing_proc)
180
  print(f"[Pipeline] Simple micro pass: {ncc_s_count} NCC -> {before_s} chamfer -> {len(cands_s)} (zone filter)")
@@ -275,12 +256,7 @@ class PatternDetectionPipeline:
275
  )
276
  _circuit = self.postprocessor.filter_junction_dots(_circuit, drawing_proc)
277
  _circuit = self.postprocessor.filter_rect_integrity(_circuit, drawing_proc)
278
- # DINOv2-verified borderline candidates (dino 0.86) bypass the
279
- # final Chamfer check — they've already been semantically confirmed.
280
- _dino_ok = [c for c in _circuit if c.get("dino_score", 0) >= 0.88]
281
- _needs_ch = [c for c in _circuit if c.get("dino_score", 0) < 0.86]
282
- _needs_ch = self.postprocessor.filter_chamfer_shape(_needs_ch, drawing_proc, pattern_proc)
283
- _circuit = _needs_ch + _dino_ok
284
  _bottom_margin = max(30, int(_drw_h * 0.04))
285
  _notes = [c for c in _notes
286
  if c["y"] + c["h"] <= _drw_h - _bottom_margin]
 
150
  # unreliable for binary line-art and rejects correctly-detected vertical
151
  # components (R2/R4/R6/R8 score < 0.84 despite being real resistors).
152
  if cands_s:
153
+ cands_s = self.postprocessor.filter_chamfer_shape(
154
+ cands_s, drawing_proc, pattern_proc, max_chamfer=3.0
 
 
 
 
155
  )
156
+ for c in cands_s:
 
 
 
 
 
 
 
 
 
 
 
 
157
  c.setdefault("dino_score", 0.0)
158
  c.setdefault("confidence", c.get("ncc_score", 0.5))
 
 
 
159
  before_s = len(cands_s)
160
  cands_s = self.postprocessor.filter_title_block(cands_s, drawing_proc)
161
  print(f"[Pipeline] Simple micro pass: {ncc_s_count} NCC -> {before_s} chamfer -> {len(cands_s)} (zone filter)")
 
256
  )
257
  _circuit = self.postprocessor.filter_junction_dots(_circuit, drawing_proc)
258
  _circuit = self.postprocessor.filter_rect_integrity(_circuit, drawing_proc)
259
+ _circuit = self.postprocessor.filter_chamfer_shape(_circuit, drawing_proc, pattern_proc)
 
 
 
 
 
260
  _bottom_margin = max(30, int(_drw_h * 0.04))
261
  _notes = [c for c in _notes
262
  if c["y"] + c["h"] <= _drw_h - _bottom_margin]