iris / hf_workspace /scripts /run_learned_batch.py
github-actions[bot]
Automated Deploy: f334c0ad60590803e1c813b87a0f019dd5fbaedd
1d21e88
Raw History Blame Contribute Delete
1.14 kB
"""Run the same learned review path used by the API on all prepared client pairs."""
import json,sys
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
import cv2
from backend.review import review_pair
ROOT=Path(__file__).resolve().parents[1];SOURCE=ROOT/'private_benchmarks/client_iris';OUT=ROOT/'private_benchmarks/learned_batch';OUT.mkdir(exist_ok=True)
rows=[]
for entry in json.loads((SOURCE/'metrics.json').read_text()):
sample=entry['sample'];folder=OUT/sample;folder.mkdir(exist_ok=True)
reference=cv2.imread(str(SOURCE/sample/'reference.png'));moving=cv2.imread(str(SOURCE/sample/'moving.png'))
result=review_pair(reference,moving,engine='learned')
for name,value in result.items():
if name!='metrics':cv2.imwrite(str(folder/(name+'.png')),value)
row=dict(sample=sample,reference=entry['reference'],moving=entry['moving'],metrics=result['metrics'])
rows.append(row);(OUT/'results.json').write_text(json.dumps(rows,indent=2))
print(json.dumps(dict(sample=sample,status=result['metrics']['status'],evaluation=result['metrics'].get('evaluation'))),flush=True)