File size: 3,575 Bytes
3e13a1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Validate the adjacent RHD shared-v1.0 tree and fingerprint its current bytes."""
import argparse, hashlib, json
import numpy as np
import torch
from rhd_common import RELEASE_ROOT, TMP_ROOT, load, save

def main():
    argparse.ArgumentParser(description='Validate the adjacent RHD shared-v1.0 release.').parse_args()
    registry=load(RELEASE_ROOT/'doc/schema.json');counts={'training':0,'evaluation':0};seen=set();views=0
    for path in sorted((RELEASE_ROOT/'data').glob('*/*/metainfo.json')):
        meta=load(path);base=path.parent;total=meta['num_frames'];views+=1
        for key in ['schema_version','view_type','split_scheme','split_source_locator','sampling','camera','components']:assert key in meta,(path,key)
        assert meta['schema_version']=='hand-warehouse/1.0' and meta['dataset_id']=='RHD' and meta['view_type']=='exo'
        frames=[json.loads(line) for line in (base/'camera/frames.jsonl').read_text(encoding='utf-8').splitlines()]
        assert len(frames)==total
        for index,frame in enumerate(frames):
            assert frame['frame_index']==index and frame['sample_id'] not in seen
            seen.add(frame['sample_id']);split=frame['sample_id'].split('/')[1];counts[split]+=1
            assert frame['source_locator']['annotation_index']==int(frame['source_frame_id'])
        for name,component in meta['components'].items():
            spec=registry['components'][component['schema_id']]
            for key in ['available','data_ref','valid_ref','axes','valid_axes','provenance','source_locator',*spec.get('required_metadata',[])]:assert key in component,(path,name,key)
            assert (base/component['data_ref']).is_file() and (base/component['valid_ref']).is_file()
            if component['data_ref'].endswith('.pt'):
                value=torch.load(base/component['data_ref'],weights_only=True).numpy();valid=torch.load(base/component['valid_ref'],weights_only=True).numpy()
                assert value.dtype==np.float32 and valid.dtype==bool
                assert list(value.shape)==[total if axis=='T' else axis for axis in spec['shape']]
                assert list(valid.shape)==[total if axis=='T' else axis for axis in spec['valid_shape']]
                assert np.isfinite(value[valid]).all()
            else:
                assert component['storage']['profile'] in spec['allowed_storage_profiles']
                for key in registry['video_metadata']['required']:assert key in component['storage'],(name,key)
            for attribute in component.get('attributes',{}).values():assert (base/attribute['data_ref']).is_file()
    assert counts=={'training':41258,'evaluation':2728},counts
    result={'passed':True,'views':views,'counts':counts,'schema_version':'hand-warehouse/1.0','scope':'current content and layout; does not independently prove official source correctness or visual quality'}
    save(TMP_ROOT/'acceptance.json',result);manifest=[]
    for path in sorted(RELEASE_ROOT.rglob('*')):
        if not path.is_file() or '.cache' in path.parts:continue
        digest=hashlib.sha256()
        with path.open('rb') as stream:
            for block in iter(lambda:stream.read(8<<20),b''):digest.update(block)
        manifest.append({'path':path.relative_to(RELEASE_ROOT).as_posix(),'size':path.stat().st_size,'sha256':digest.hexdigest()})
    save(TMP_ROOT/'files.sha256.json',{'scope':result['scope'],'files':manifest,'bytes':sum(x['size'] for x in manifest)})
    print(json.dumps(result,ensure_ascii=False))

if __name__=='__main__':main()