Duy commited on
Commit
ed0c8d7
·
1 Parent(s): 7330864

fix: eval_drawings.py — correct template pairings and document baselines

Browse files
Files changed (1) hide show
  1. scripts/eval_drawings.py +43 -30
scripts/eval_drawings.py CHANGED
@@ -1,5 +1,11 @@
1
- """Compare DINODense ON vs OFF on the 6 real drawings using the resistor
2
- (simple) template — this is the path where DINODense Pass C actually activates.
 
 
 
 
 
 
3
  """
4
  import sys
5
  import os
@@ -10,39 +16,46 @@ from src.pipeline import PatternDetectionPipeline # noqa: E402
10
 
11
  DRAWINGS_DIR = r"D:\Sotatek_Assessment\drawings"
12
 
 
 
 
 
13
 
14
- def main():
15
- pattern = os.path.join(DRAWINGS_DIR, "test_2.png") # resistor simple template
16
- drawings = [os.path.join(DRAWINGS_DIR, f"{i}.png") for i in range(1, 7)]
 
 
17
 
18
- if not os.path.exists(pattern):
19
- print(f"MISSING pattern: {pattern}")
20
- return
21
 
 
 
22
  summary = {}
23
- for mode_name, flag in [("dense_ON", True), ("dense_OFF", False)]:
24
- print(f"\n########## MODE: {mode_name} ##########")
25
- pipe = PatternDetectionPipeline(config={"use_dino_dense": flag})
26
- for dpath in drawings:
27
- name = os.path.basename(dpath)
28
- if not os.path.exists(dpath):
29
- print(f"SKIP {name}")
30
- continue
31
- try:
32
- result = pipe.detect_auto(pattern, dpath, return_visualization=False)
33
- n = result.get("total_detections")
34
- except Exception as e:
35
- n = f"ERR:{e}"
36
- summary[(mode_name, name)] = n
37
- print(f" {name}: {n}")
38
-
39
- print("\n========== SUMMARY (resistor template) ==========")
 
 
 
 
40
  for i in range(1, 7):
41
- name = f"{i}.png"
42
- on = summary.get(("dense_ON", name))
43
- off = summary.get(("dense_OFF", name))
44
- flag = " <-- DIFF" if on != off else ""
45
- print(f" {name}: ON={on} OFF={off}{flag}")
46
 
47
 
48
  if __name__ == "__main__":
 
1
+ """Evaluate the pipeline on the 6 assessment drawings.
2
+
3
+ Template pairings (established in session 5):
4
+ Drawing 1 (resistor circuit) + test_pattern_d1_2.png -> baseline 10 dets
5
+ Drawing 4 (bridge rectifier) + test_pattern_d1.png -> baseline 4 dets
6
+ Drawings 2,3,5,6 + test_pattern_d1_2.png -> expected 0 dets
7
+
8
+ DINODense Pass C was shown to be dormant (ON==OFF everywhere) in session 6.
9
  """
10
  import sys
11
  import os
 
16
 
17
  DRAWINGS_DIR = r"D:\Sotatek_Assessment\drawings"
18
 
19
+ # Primary evaluation: resistor template vs all 6 drawings
20
+ RESISTOR_PAT = os.path.join(DRAWINGS_DIR, "test_pattern_d1_2.png")
21
+ # Secondary: bridge rectifier template vs drawing 4
22
+ BRIDGE_PAT = os.path.join(DRAWINGS_DIR, "test_pattern_d1.png")
23
 
24
+ BASELINES = {
25
+ ("resistor", "1.png"): 10,
26
+ ("resistor", "4.png"): None, # not expected
27
+ ("bridge", "4.png"): 4,
28
+ }
29
 
 
 
 
30
 
31
+ def main():
32
+ pipe = PatternDetectionPipeline()
33
  summary = {}
34
+
35
+ print("\n===== Resistor template (test_pattern_d1_2.png) =====")
36
+ for i in range(1, 7):
37
+ dpath = os.path.join(DRAWINGS_DIR, f"{i}.png")
38
+ if not os.path.exists(dpath):
39
+ print(f" SKIP {i}.png (not found)")
40
+ continue
41
+ r = pipe.detect_auto(RESISTOR_PAT, dpath, return_visualization=False)
42
+ n = r["total_detections"]
43
+ summary[("resistor", f"{i}.png")] = n
44
+ base = BASELINES.get(("resistor", f"{i}.png"))
45
+ tag = f" (baseline {base})" if base is not None else ""
46
+ print(f" {i}.png: {n}{tag}")
47
+
48
+ print("\n===== Bridge-rectifier template (test_pattern_d1.png) vs drawing 4 =====")
49
+ dpath = os.path.join(DRAWINGS_DIR, "4.png")
50
+ r = pipe.detect_auto(BRIDGE_PAT, dpath, return_visualization=False)
51
+ n = r["total_detections"]
52
+ print(f" 4.png: {n} (baseline 4)")
53
+
54
+ print("\n===== SUMMARY =====")
55
  for i in range(1, 7):
56
+ k = ("resistor", f"{i}.png")
57
+ if k in summary:
58
+ print(f" resistor + {i}.png: {summary[k]}")
 
 
59
 
60
 
61
  if __name__ == "__main__":