-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfp_test.py
More file actions
65 lines (53 loc) · 2.04 KB
/
Copy pathfp_test.py
File metadata and controls
65 lines (53 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Quick false-positive check: run inference on the test split and flag any
frames where confidences are suspiciously low (likely FP-prone range).
Usage: python fp_test.py [--conf 0.35] [--weights path/to/best.pt]
"""
import argparse
from pathlib import Path
from ultralytics import YOLO
def main():
parser = argparse.ArgumentParser(description="False-positive diagnostic tool")
parser.add_argument(
"--weights",
default="runs/detect/coin_detector_nano_v2/weights/best.pt",
help="Path to model weights",
)
parser.add_argument(
"--conf", type=float, default=0.35, help="Confidence threshold"
)
parser.add_argument(
"--source",
default="datasets/images/test",
help="Image folder to scan",
)
args = parser.parse_args()
model = YOLO(args.weights)
source = Path(args.source)
if not source.exists():
print(f"Source folder not found: {source}")
return
images = sorted(
p for p in source.iterdir() if p.suffix.lower() in {".jpg", ".jpeg", ".png"}
)
print(f"Scanning {len(images)} images at conf={args.conf}\n")
low_conf_detections = []
total_dets = 0
for img in images:
results = model(str(img), conf=args.conf, verbose=False)
boxes = results[0].boxes
total_dets += len(boxes)
for box in boxes:
c = float(box.conf[0])
if c < 0.50: # flag anything in the "shaky confidence" range
cls_name = model.names[int(box.cls[0])]
low_conf_detections.append((img.name, cls_name, c))
print(f"Total detections: {total_dets}")
if low_conf_detections:
print(f"\n⚠ {len(low_conf_detections)} low-confidence detections (conf < 0.50):")
for name, cls, c in low_conf_detections:
print(f" {name:40s} {cls:10s} conf={c:.3f}")
print("\nThese are the most likely false positives. Inspect the images above.")
else:
print("\n✅ No low-confidence detections — looks clean.")
if __name__ == "__main__":
main()