Spaces:
Paused
Paused
Download scripts/score_landmarks.py from modventures/iris: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/modventures/iris/resolve/main/scripts/score_landmarks.py
- Command line
-
hf download hf://spaces/modventures/iris/scripts/score_landmarks.py
-
curl -L -o score_landmarks.py https://huggingface.co/spaces/modventures/iris/resolve/main/scripts/score_landmarks.py
1.63 kB
| """Score independently human-marked landmarks against a saved research mapping.""" | |
| import argparse,json | |
| from pathlib import Path | |
| import cv2,numpy as np | |
| p=argparse.ArgumentParser();p.add_argument('annotations',type=Path);args=p.parse_args() | |
| data=json.loads(args.annotations.read_text());sample=str(data['sample']) | |
| if sample not in list('123456') or data.get('coordinate_frame')!='native_2200_crop':raise ValueError('Unsupported sample or coordinate frame') | |
| points=data['points'] | |
| if len(points)<6:raise ValueError('At least six completed landmarks are required') | |
| ref=np.float32([x['reference'] for x in points]);mov=np.float32([x['moving'] for x in points]) | |
| if ref.shape!=(len(points),2) or mov.shape!=ref.shape or not np.isfinite(ref).all() or not np.isfinite(mov).all() or np.any(ref<0) or np.any(ref>2199) or np.any(mov<0) or np.any(mov>2199):raise ValueError('Invalid landmark coordinates') | |
| root=Path(__file__).resolve().parents[1]/'private_benchmarks/research' | |
| method='loftr_mesh' if sample=='1' else 'loftr_patch_mesh' | |
| mapping=np.load(root/f'{sample}-{method}'/'mapping.npz')['map'] | |
| pred=cv2.remap(mapping,ref[:,0,None],ref[:,1,None],cv2.INTER_LINEAR)[:,0] | |
| error=np.linalg.norm(pred-mov,axis=1) | |
| result=dict(sample=sample,count=len(points),median_px=float(np.median(error)),p95_px=float(np.percentile(error,95)),max_px=float(error.max()),errors_px=error.tolist(),note='Measured against human-marked coordinates; annotation uncertainty applies. Sample 1 remains a rejected research candidate.') | |
| output=args.annotations.with_suffix('.score.json');output.write_text(json.dumps(result,indent=2));print(json.dumps(result,indent=2)) | |