Download source/reconstruct_generation_report.py from DanielNguyen121/DisEF-Cars: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/datasets/DanielNguyen121/DisEF-Cars/resolve/main/source/reconstruct_generation_report.py
- Command line
-
hf download hf://datasets/DanielNguyen121/DisEF-Cars/source/reconstruct_generation_report.py
-
curl -L -o reconstruct_generation_report.py https://huggingface.co/datasets/DanielNguyen121/DisEF-Cars/resolve/main/source/reconstruct_generation_report.py
3.03 kB
| from pathlib import Path | |
| from huggingface_hub import HfApi | |
| from PIL import Image | |
| from collections import Counter | |
| import json,hashlib | |
| r=Path('/marimo/disef_cars');run=r/'runs/generation_seed_1';cfg=json.loads((r/'configs/generation_config.json').read_text());state=json.loads((run/'state/cars_disef_state.json').read_text());recovery=json.loads((run/'state/recovery_state.json').read_text());support=json.loads((r/'manifests/fewshot_seed_1_leakfree.json').read_text());train={str(r/'data/prepared/StanfordCars'/p) for ps in support['support_by_class'].values() for p in ps} | |
| assert state['status']=='COMPLETED' and state['completed']==state['target']==12544 | |
| assert len(train)==3136 and support['support_sha256']==cfg['selected_sources_sha256'] | |
| records=list(state['records'].values());assert len(records)==12544 | |
| per=Counter();digests=set();fallback=0;strict=0 | |
| for x in records: | |
| assert x['completion_status']=='COMPLETE' and x['source_image'] in train and x['caption_source_image'] in train | |
| assert x['class_folder']==f"class_{x['class_id']:03d}" | |
| p=run/x['synthetic_filename'];assert p.is_file() and p.parent.name==x['class_folder'] | |
| with Image.open(p) as im:im.load();assert im.format=='JPEG' and im.size==(512,512) | |
| sha=hashlib.file_digest(p.open('rb'),'sha256').hexdigest();assert sha==x['sha256'] and sha not in digests;digests.add(sha);per[x['class_folder']]+=1 | |
| if x.get('fallback_accept'): | |
| assert not x.get('filter_pass') and x.get('recovery_variant')==recovery['variant'];fallback+=1 | |
| else:assert x.get('filter_pass') is True;strict+=1 | |
| assert len(per)==196 and min(per.values())==max(per.values())==64 and fallback==348 and strict==12196 | |
| archive=r/'data/synthetic/cars_disef_images.zip';sha=hashlib.file_digest(archive.open('rb'),'sha256').hexdigest();assert sha=='f611aa43beb17308e06a725f9cc4ec9c470f6341d0384a2af4dc3348ab2daa11' | |
| repo='DanielNguyen121/DisEF-datasets';rev='85613271c5642b570b61abfa78e350a1c360d6b3';info=HfApi().repo_info(repo,repo_type='dataset',revision=rev,files_metadata=True);remote=next(x for x in info.siblings if x.rfilename==archive.name);assert remote.size==archive.stat().st_size and remote.lfs.sha256==sha | |
| report={'variant':recovery['variant'],'strict_filter_accepted':strict,'reference_fallback_accepted':fallback,'classes':196,'valid_images':12544,'per_class_min':64,'per_class_max':64,'generated_attempts':state['attempted'],'rejected':state['rejected'],'retried':state['retried'],'failed':state['failed'],'support_sha256':support['support_sha256'],'archive_filename':archive.name,'archive_sha256':sha,'archive_bytes':archive.stat().st_size,'remote_repo':repo,'remote_revision':rev,'remote_verified':True,'generation_config':cfg,'recovery_protocol':recovery,'restored_from_remote_state':True,'validated_against_archive':True} | |
| out=r/'reports/generation_report.json';out.parent.mkdir(parents=True,exist_ok=True);tmp=out.with_suffix('.tmp');tmp.write_text(json.dumps(report,indent=2,sort_keys=True));tmp.replace(out);print('GENERATION_REPORT_RECONSTRUCTED',strict,fallback,sha,flush=True) | |