Download evaluation/evaluate_timeline.py from KlyffInc/pcb-anomaly-detection: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/KlyffInc/pcb-anomaly-detection/resolve/main/evaluation/evaluate_timeline.py
- Command line
-
hf download hf://KlyffInc/pcb-anomaly-detection/evaluation/evaluate_timeline.py
-
curl -L -o evaluate_timeline.py https://huggingface.co/KlyffInc/pcb-anomaly-detection/resolve/main/evaluation/evaluate_timeline.py
3.03 kB
| #!/usr/bin/env python3 | |
| """Run a non-metric integration smoke test on representative video timestamps.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import platform | |
| import sys | |
| import time | |
| from dataclasses import asdict | |
| from pathlib import Path | |
| import cv2 | |
| import openvino as ov | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from inference import PcbAnomalyDetector # noqa: E402 | |
| EVENTS = [ | |
| (27.0, "Spur", False), | |
| (35.0, "Open_circuit", True), | |
| (57.0, "Mouse_bite", True), | |
| (63.0, "Short", True), | |
| (173.0, "Spurious_copper", True), | |
| (189.0, "Missing_hole", True), | |
| ] | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("video", type=Path) | |
| parser.add_argument("--output", type=Path, default=Path(__file__).with_name("smoke-test.json")) | |
| parser.add_argument("--confidence", type=float, default=0.60) | |
| args = parser.parse_args() | |
| capture = cv2.VideoCapture(str(args.video)) | |
| if not capture.isOpened(): | |
| raise SystemExit(f"Could not open video: {args.video}") | |
| detector = PcbAnomalyDetector() | |
| samples = [] | |
| timings = [] | |
| for seconds, expected, supported in EVENTS: | |
| capture.set(cv2.CAP_PROP_POS_MSEC, seconds * 1000) | |
| ok, frame = capture.read() | |
| if not ok: | |
| raise SystemExit(f"Could not read timestamp {seconds}") | |
| started = time.perf_counter() | |
| detections = detector.predict(frame, confidence=args.confidence) | |
| timings.append((time.perf_counter() - started) * 1000) | |
| samples.append({ | |
| "timestamp_seconds": seconds, | |
| "event_label": expected, | |
| "event_supported_by_model": supported, | |
| "detected_labels": sorted({item.label for item in detections}), | |
| "detections": [asdict(item) for item in detections], | |
| }) | |
| capture.release() | |
| result = { | |
| "test_type": "integration_smoke_test_not_accuracy_evaluation", | |
| "model_version": "pcb_vision_obj_v0.01", | |
| "confidence_threshold": args.confidence, | |
| "video_metadata": {"width": 1408, "height": 768, "fps": 25.0, "duration_seconds": 208.0}, | |
| "samples": samples, | |
| "timing": { | |
| "scope": "preprocess_plus_synchronous_inference_plus_postprocess_excludes_compilation_and_io", | |
| "mean_ms_per_sample": sum(timings) / len(timings), | |
| "sample_count": len(timings), | |
| "host": platform.processor() or platform.machine(), | |
| }, | |
| "runtime": {"python": platform.python_version(), "openvino": ov.__version__, "opencv": cv2.__version__}, | |
| "limitations": [ | |
| "Event windows are coarse demonstration-video metadata, not bounding-box ground truth.", | |
| "This result must not be reported as mAP, precision, recall, or production latency SLA.", | |
| ], | |
| } | |
| args.output.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(result, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |