Spaces:
Paused
Paused
Download benchmark.py from modventures/iris: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/modventures/iris/resolve/main/benchmark.py
- Command line
-
hf download hf://spaces/modventures/iris/benchmark.py
-
curl -L -o benchmark.py https://huggingface.co/spaces/modventures/iris/resolve/main/benchmark.py
3.05 kB
| """Generate deterministic test pairs and a browsable report; run from repo root.""" | |
| from pathlib import Path | |
| import html | |
| import json | |
| import cv2 | |
| import numpy as np | |
| from backend.registration import register, RegistrationError | |
| from synthetic_cases import CASE_NAMES, make_case, mapping_errors | |
| out = Path('reports') | |
| out.mkdir(exist_ok=True) | |
| ref = cv2.resize(cv2.imread('fixtures/synthetic-iris.png'), (1000, 1000)) | |
| cv2.imwrite(str(out/'reference.png'), ref) | |
| rows = [] | |
| cards = [] | |
| for name in CASE_NAMES: | |
| moving, truth_points, moving_points = make_case(ref, name) | |
| cv2.imwrite(str(out/f'{name}-moving.jpg'), moving) | |
| try: | |
| result = register(ref, moving, return_maps=True) | |
| errors = mapping_errors(result['sampling_map'], truth_points, moving_points) | |
| row = dict(case=name, median_error_px=float(np.median(errors)), p95_error_px=float(np.percentile(errors,95)), | |
| status='PASS' if np.percentile(errors,95)<1 else 'LIMITATION', **result['metrics']) | |
| for key, img in result.items(): | |
| if key not in ('metrics', 'sampling_map'): | |
| cv2.imwrite(str(out/f'{name}-{key}.png'), img) | |
| cards.append(f'<section><h2>{name}: {row["status"]}</h2><p>Independent grid error: median {row["median_error_px"]:.3f}px · p95 {row["p95_error_px"]:.3f}px</p><div>'+''.join(f'<figure><a href="{name}-{key}.{ext}"><img src="{name}-{key}.{ext}"></a><figcaption>{key}</figcaption></figure>' for key,ext in [('moving','jpg'),('global_aligned','png'),('overlay','png'),('composite','png')])+'</div></section>') | |
| except RegistrationError as exc: | |
| row = dict(case=name, status='REJECTED', reason=str(exc)) | |
| cards.append(f'<section><h2>{name}: REJECTED</h2><p>{html.escape(str(exc))} No composite produced.</p><div><figure><a href="{name}-moving.jpg"><img src="{name}-moving.jpg"></a><figcaption>Moving image with known local distortion</figcaption></figure><figure><img src="reference.png"><figcaption>Reference</figcaption></figure></div></section>') | |
| rows.append(row) | |
| (out/'metrics.json').write_text(json.dumps(rows, indent=2)) | |
| (out/'index.html').write_text('<!doctype html><meta charset="utf-8"><title>Synthetic registration benchmark</title><style>body{background:#111b22;color:#e2e9ed;font:16px system-ui;margin:40px}p{color:#acbcc6}section{margin:40px 0}section div{display:flex;gap:16px}figure{margin:0;flex:1;min-width:0}img{width:100%}a{color:#72d7b5}</style><h1>Synthetic iris registration benchmark</h1><p>One AI-generated fixture, deterministic transformations. These are not real client photographs. Error is measured in moving-image pixels using the complete backward sampling map at independent known-coordinate iris grid points, not fitting matches. PASS means p95 < 1 pixel at 1000 × 1000. Click images for full resolution.</p><a href="reference.png">Reference image</a> · <a href="metrics.json">Full measurements</a>'+''.join(cards)) | |
| print(json.dumps([{k:r[k] for k in ['case','status','median_error_px','p95_error_px'] if k in r} for r in rows], indent=2)) | |