shaoyz's picture
Organize HOT3D and ARCTIC shared scripts
c91cf46 verified
Raw History Blame
3.76 kB
"""Download bounded official pilot inputs; keep archives intact. No upstream code execution."""
from pathlib import Path
import concurrent.futures, hashlib, json, requests
ROOT = Path(__file__).resolve().parents[1] / 'hand-datasets'
REFS = {
'Dex-YCB': ('NVlabs/dex-ycb-toolkit', ['README.md','dex_ycb_toolkit/dex_ycb.py','dex_ycb_toolkit/sequence_loader.py']),
'VISOR': ('epic-kitchens/VISOR-VIS', ['README.md','vis.py']),
'H2O': ('taeinkwon/h2odataset', ['README.md','download_script.py']),
'HOI4D': ('leolyliu/HOI4D-Instructions', ['README.md','utils/parse_2Dmask_img.py','utils/color_map.py']),
'ARCTIC': ('zc-alexfan/arctic', ['docs/data/README.md','docs/data/data_doc.md']),
'FreiHAND': ('lmb-freiburg/freihand', ['README.md','utils/model.py','utils/fh_utils.py','view_samples.py']),
'RHD': ('lmb-freiburg/hand3d', ['README.md','create_binary_db.py']),
'HOT3D': ('facebookresearch/hot3d', ['README.md','hot3d/data_loaders/loader_hand_poses.py']),
'OakInk2': ('oakink/OakInk2', ['README.md']),
'ReInterHand': ('facebookresearch/InterWild', ['tool/ReInterHand/download/download_checksum_framelist.py','tool/ReInterHand/download/download_ego_per_frame.py','tool/ReInterHand/download/download_mano_fits.py']),
}
BASE='https://data.bris.ac.uk/datasets/2v6cgv1x04ol22qp9rm9x2j6a7/'
def sha(p):
h=hashlib.sha256()
with p.open('rb') as f:
for b in iter(lambda:f.read(1024*1024),b''):h.update(b)
return h.hexdigest()
def fetch(dataset, url, relative, limit=30_000_000):
p=ROOT/dataset/'raw'/relative;p.parent.mkdir(parents=True,exist_ok=True)
receipt=p.with_name(p.name+'.receipt.json')
if p.exists() and receipt.exists():
info=json.loads(receipt.read_text()); assert sha(p)==info['sha256'];return info
part=p.with_name(p.name+'.part')
with requests.get(url,stream=True,headers={'Accept-Encoding':'identity'},timeout=(15,40)) as r:
r.raise_for_status(); expected=int(r.headers.get('Content-Length',0))
if expected>limit:raise ValueError(f'File exceeds pilot limit: {expected}')
size=0
with part.open('wb') as f:
for chunk in r.iter_content(1024*1024):
size+=len(chunk)
if size>limit:raise ValueError('Stream exceeds pilot limit')
f.write(chunk)
if expected and not r.headers.get('Content-Encoding') and size!=expected:raise ValueError('Incomplete transfer')
part.replace(p)
info={'url':url,'path':str(p.relative_to(ROOT/dataset)), 'bytes':size,'sha256':sha(p),'official_checksum':None,'verification':'HTTP success; content length where supplied; locally computed SHA256'}
receipt.write_text(json.dumps(info,indent=2),encoding='utf-8');return info
def reference(item):
name,(repo,paths)=item;results=[]
for section in ['raw/doc','raw/script','raw/data','pilot-v0/doc','pilot-v0/script','pilot-v0/data']:(ROOT/name/section).mkdir(parents=True,exist_ok=True)
for path in paths:
try:results.append(fetch(name,f'https://raw.githubusercontent.com/{repo}/HEAD/{path}',('script/' if path.endswith('.py') else 'doc/')+path))
except Exception as e:results.append({'path':path,'error':str(e)})
return name,results
def main():
results=dict(concurrent.futures.ThreadPoolExecutor(6).map(reference,REFS.items()))
for path in ['GroundTruth-SparseAnnotations/annotations/train/P01_03.json','GroundTruth-SparseAnnotations/rgb_frames/train/P01/P01_03.zip','EPIC_100_noun_classes_v2.csv','frame_mapping.json']:
try:results['VISOR'].append(fetch('VISOR',BASE+path,'data/'+path))
except Exception as e:results['VISOR'].append({'path':path,'error':str(e)})
for name,rows in results.items():
(ROOT/name/'raw/doc/download_manifest.json').write_text(json.dumps(rows,indent=2),encoding='utf-8')
print(name,[(r.get('path'),r.get('bytes',r.get('error'))) for r in rows],flush=True)
if __name__=='__main__':main()