"""Compare saved official test predictions and reports, without model execution.""" import csv,json import numpy as np from backend.config import ROOT,CATEGORIES from scripts.benchmark_official import write if __name__=='__main__': old=json.loads((ROOT/'results/official_evaluation.json').read_text()) new=json.loads((ROOT/'results/highres_evaluation.json').read_text()) assert set(new['categories'])==set(CATEGORIES) rows=[] for category in CATEGORIES: a=json.loads((ROOT/'experiments/official_visa_v1'/category/'split.json').read_text()) b=json.loads((ROOT/'experiments/dinov2_highres_v1'/category/'split.json').read_text()) assert {r['image']:r['sha256'] for r in a['test']}=={r['image']:r['sha256'] for r in b['test']} before=old['categories'][category]['benchmark_mean'];after=new['categories'][category]['benchmark_mean'] rows.append({'category':category,'old_image_auroc':before['auroc'],'new_image_auroc':after['auroc'], 'auroc_change_pp':(after['auroc']-before['auroc'])*100,'old_image_ap':before['average_precision'], 'new_image_ap':after['average_precision'],'old_pixel_ap':before['pixel_average_precision'], 'new_pixel_ap':after['pixel_average_precision']}) for report in (old,new): for metric in report['macro_mean']: assert abs(report['macro_mean'][metric]-np.mean([c['benchmark_mean'][metric] for c in report['categories'].values()]))<1e-12 result={'status':'passed','same_official_test_identities_and_content_hashes':True, 'baseline_macro':old['macro_mean'],'candidate_macro':new['macro_mean'],'candidate_macro_std':new['macro_std'], 'all_categories':rows,'image_auroc_regressions':[r['category'] for r in rows if r['auroc_change_pp']<0], 'pixel_ap_regressions':[r['category'] for r in rows if r['new_pixel_ap']