Download ReInterHand/shared-v1.0/script/validate_release.py from ParityLab/Hand-Datasets-Raw: direct link, hf CLI and curl.
- Browser
- Download file 6.27 kB
-
https://huggingface.co/datasets/ParityLab/Hand-Datasets-Raw/resolve/refs%2Fpr%2F7/ReInterHand/shared-v1.0/script/validate_release.py
- Command line
-
hf download hf://datasets/ParityLab/Hand-Datasets-Raw@refs/pr/7/ReInterHand/shared-v1.0/script/validate_release.py
-
curl -L -o validate_release.py https://huggingface.co/datasets/ParityLab/Hand-Datasets-Raw/resolve/refs%2Fpr%2F7/ReInterHand/shared-v1.0/script/validate_release.py
6.27 kB
| """Read-only release validation; --tensors/--media explicitly broaden coverage.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| def load(p): | |
| return json.loads(p.read_text(encoding='utf-8-sig')) | |
| def refs(value): | |
| if isinstance(value, dict): | |
| for k, v in value.items(): | |
| if k.endswith('_ref') and isinstance(v, str): | |
| yield k, v | |
| elif k != 'source_locator': | |
| yield from refs(v) | |
| elif isinstance(value, list): | |
| for v in value: | |
| yield from refs(v) | |
| def check(release, tensors=False, media=False, output=None, sequence_id=None): | |
| if tensors: | |
| import torch | |
| torch.set_num_threads(1) | |
| results=[] | |
| sequences=sorted(p for p in (release/'data').iterdir() if p.is_dir()) | |
| if sequence_id is not None: sequences=[p for p in sequences if p.name==sequence_id] | |
| if not sequences: | |
| raise RuntimeError('No sequences found') | |
| for sequence in sequences: | |
| errors=[]; count=0; frames_total=0 | |
| views=sorted(p for p in sequence.iterdir() if p.is_dir()) | |
| if not views: errors.append('no views') | |
| for view in views: | |
| try: | |
| m=load(view/'metainfo.json'); T=m['num_frames']; count+=1; frames_total+=T | |
| assert isinstance(T,int) and T>0, 'invalid T' | |
| assert m['sequence_id']==sequence.name and m['camera_id']==view.name, 'identity mismatch' | |
| assert m['view_type'] in ('ego','exo','unknown'), 'view_type' | |
| assert m['split'] in ('train','val','test','unknown'), 'split' | |
| assert m['schema_version']=='hand-warehouse/1.0', 'schema_version' | |
| frame_path=view/m['sampling']['frames_ref'] | |
| frames=[json.loads(line) for line in frame_path.read_text().splitlines() if line.strip()] | |
| assert len(frames)==T, 'frame count mismatch' | |
| assert [r['frame_index'] for r in frames]==list(range(T)), 'frame_index' | |
| assert all(r.get('source_frame_id') is not None for r in frames), 'source_frame_id missing' | |
| assert len({str(r['source_frame_id']) for r in frames})==T, 'duplicate source IDs' | |
| for key, rel in refs(m.get('components',{})): | |
| p=(view/rel).resolve() | |
| assert p.is_relative_to(release.resolve()), 'reference escapes release' | |
| assert p.is_file(), 'missing reference '+rel | |
| for name,c in m['components'].items(): | |
| if not isinstance(c,dict) or not c.get('available',True): continue | |
| rel=c.get('data_ref') | |
| if not rel: continue | |
| p=view/rel | |
| if tensors and p.suffix=='.pt': | |
| x=torch.load(p,map_location='cpu',weights_only=True) | |
| assert isinstance(x,torch.Tensor), name+': not tensor' | |
| if c.get('axes',[None])[0]=='T': assert x.shape[0]==T, name+': T' | |
| valid_ref=c.get('valid_ref') | |
| if valid_ref: | |
| valid=torch.load(view/valid_ref,map_location='cpu',weights_only=True) | |
| assert valid.dtype==torch.bool, name+': valid dtype' | |
| assert valid.shape[0]==T, name+': valid T' | |
| if x.is_floating_point(): | |
| assert x.dtype==torch.float32, name+': float dtype' | |
| mask=valid | |
| while mask.ndim<x.ndim: mask=mask.unsqueeze(-1) | |
| mask=mask.expand_as(x) | |
| assert torch.isfinite(x[mask]).all(), name+': valid nonfinite' | |
| if name=='extrinsic': | |
| assert x.shape==(T,4,4), 'extrinsic shape' | |
| R=x[:,:3,:3] | |
| assert torch.allclose(R@R.transpose(1,2),torch.eye(3).expand(T,3,3),atol=1e-3), 'rotation orthogonality' | |
| assert torch.allclose(torch.det(R),torch.ones(T),atol=1e-3), 'rotation determinant' | |
| if media and p.suffix=='.mkv': | |
| probe=json.loads(subprocess.check_output(['ffprobe','-v','error','-count_frames','-select_streams','v:0','-show_entries','stream=nb_read_frames,width,height','-of','json',str(p)]))['streams'][0] | |
| assert int(probe['nb_read_frames'])==T, name+': media T' | |
| assert [probe['width'],probe['height']]==m['camera']['image_size'], name+': media dimensions' | |
| except Exception as exc: | |
| errors.append(view.name+': '+str(exc)) | |
| row={'sequence_id':sequence.name,'views':count,'frame_rows':frames_total,'errors':errors,'status':'failed' if errors else 'passed'} | |
| results.append(row) | |
| if output: | |
| target=output/'sequences'/f'{sequence.name}.json'; target.parent.mkdir(parents=True,exist_ok=True) | |
| target.write_text(json.dumps(row,indent=2)+'\n') | |
| result={'scope':{'metadata_frame_mapping_references':True,'tensors':tensors,'media_decode_frame_count':media,'source_pixel_equivalence':False,'independent_official_digest':False},'sequences':len(results),'views':sum(x['views'] for x in results),'frame_rows':sum(x['frame_rows'] for x in results),'errors':[{'sequence':x['sequence_id'],'errors':x['errors']} for x in results if x['errors']]} | |
| result['status']='failed' if result['errors'] else 'passed' | |
| if output: | |
| output.mkdir(parents=True,exist_ok=True); (output/'summary.json').write_text(json.dumps(result,indent=2)+'\n') | |
| return result | |
| if __name__=='__main__': | |
| parser=argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--tensors',action='store_true') | |
| parser.add_argument('--media',action='store_true') | |
| parser.add_argument('--output',type=Path) | |
| parser.add_argument('--sequence',help='Optional single sequence; default checks all sequences') | |
| args=parser.parse_args() | |
| result=check(Path(__file__).resolve().parent.parent,args.tensors,args.media,args.output,args.sequence) | |
| print(json.dumps(result)); sys.exit(bool(result['errors'])) | |