Hand-Datasets-Raw / FreiHAND /shared-v1.0 /script /validate_freihand.py
shaoyz's picture
Unify hand-warehouse schema and add RHD/FreiHAND view types
3e13a1e verified
Raw History Blame
3.73 kB
"""Validate the adjacent FreiHAND shared-v1.0 tree and fingerprint its current bytes."""
import argparse, hashlib, json
import numpy as np
import torch
from freihand_common import RELEASE_ROOT, TMP_ROOT, load, save
def main():
argparse.ArgumentParser(description='Validate the adjacent FreiHAND 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['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']); source_split = frame['sample_id'].split('/')[1]; counts[source_split] += 1
modulus = 32560 if source_split == 'training' else 3960
assert frame['source_locator']['annotation_index'] == int(frame['source_frame_id']) % modulus
for name, component in meta['components'].items():
definition = registry['components'][component['schema_id']]
required = ['available','data_ref','axes','valid_ref','valid_axes','provenance','source_locator',*definition.get('required_metadata',[])]
for key in required: assert key in component, (path,name,key)
assert (base/component['data_ref']).is_file()
valid = torch.load(base/component['valid_ref'], weights_only=True).numpy(); assert valid.dtype == bool
assert list(valid.shape) == [total if axis == 'T' else axis for axis in definition['valid_shape']]
if component['data_ref'].endswith('.pt'):
value = torch.load(base/component['data_ref'], weights_only=True).numpy()
assert value.dtype == np.float32
assert list(value.shape) == [total if axis == 'T' else axis for axis in definition['shape']]
assert np.isfinite(value[valid]).all() and np.isnan(value[~valid]).all()
else:
assert component['storage']['profile'] in definition['allowed_storage_profiles']
for key in registry['video_metadata']['required']: assert key in component['storage'], (name,key)
assert counts == {'training':130240,'evaluation':3960}, 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()