Spaces:
Paused
Paused
Download scripts/validate_matcher_patches.py from modventures/iris: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/modventures/iris/resolve/main/scripts/validate_matcher_patches.py
- Command line
-
hf download hf://spaces/modventures/iris/scripts/validate_matcher_patches.py
-
curl -L -o validate_matcher_patches.py https://huggingface.co/spaces/modventures/iris/resolve/main/scripts/validate_matcher_patches.py
1.41 kB
| import sys,json | |
| from pathlib import Path | |
| sys.path.insert(0,str(Path(__file__).resolve().parents[1])) | |
| import cv2,numpy as np | |
| from backend.experimental.patch_validation import validate_patches | |
| ROOT=Path(__file__).resolve().parents[1];OUT=ROOT/'private_benchmarks/research' | |
| rows=json.loads((OUT/'matchers.json').read_text()) | |
| for name in ['iris_sift','loftr']: | |
| for n in range(1,7): | |
| path=ROOT/'private_benchmarks/client_iris'/str(n) | |
| a=cv2.imread(str(path/'reference.png'));b=cv2.imread(str(path/'moving.png')) | |
| pairs=np.load(OUT/f'{n}-{name}-matches.npz') | |
| dst,src=validate_patches(a,b,pairs['reference'],pairs['moving']) | |
| method=name+'_patch';np.savez_compressed(OUT/f'{n}-{method}-matches.npz',reference=dst,moving=src) | |
| row=dict(sample=n,method=method,matches=len(src),input_matches=len(pairs['reference'])) | |
| if len(src)>=16: | |
| hold=((dst[:,0]//150+dst[:,1]//150).astype(int)%5)==0 | |
| if hold.sum()>=8: | |
| h,ins=cv2.findHomography(src[~hold],dst[~hold],cv2.USAC_MAGSAC,4) | |
| if h is not None: | |
| err=np.linalg.norm(cv2.perspectiveTransform(src[hold,None],h)[:,0]-dst[hold],axis=1) | |
| row.update(train_inliers=int(ins.sum()),train_count=int((~hold).sum()),test_count=int(hold.sum()),heldout_median=float(np.median(err)),heldout_p95=float(np.percentile(err,95)),matrix=h.tolist()) | |
| rows.append(row);print(json.dumps(row),flush=True) | |
| (OUT/'matchers-patch.json').write_text(json.dumps(rows,indent=2)) | |