shaoyz's picture
Complete ReInterHand and OakInk2 release docs and reproducible scripts
bdd9ed1 verified
Raw History Blame
4.76 kB
"""Release-local entry point. See README.md; no --release argument is needed."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import subprocess
import sys
SCRIPT=Path(__file__).resolve().parent
RELEASE=SCRIPT.parent
ROOT=RELEASE.parent
sys.dont_write_bytecode=True
def main():
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('command',choices=['preflight','inventory','pilot','full','validate','review','checksums'])
p.add_argument('--sequence',help='OakInk sequence; ReInterHand capture for pilot')
p.add_argument('--segment',help='ReInterHand pilot action')
p.add_argument('--tensors',action='store_true')
p.add_argument('--media',action='store_true')
a=p.parse_args()
c=json.loads((SCRIPT/'config.json').read_text())
def path(k):
v=Path(c[k]); return v if v.is_absolute() else (ROOT/v).resolve()
env=os.environ.copy()
env['PYTHONDONTWRITEBYTECODE']='1'
for k in ('OMP_NUM_THREADS','MKL_NUM_THREADS','OPENBLAS_NUM_THREADS','NUMEXPR_NUM_THREADS'): env[k]='1'
packages=path('packages')
env['PYTHONPATH']=str(packages)+os.pathsep+env.get('PYTHONPATH','')
def run(name,args):
subprocess.run([sys.executable,str(SCRIPT/name),*map(str,args)],check=True,env=env)
reinter=c['dataset']=='ReInterHand'
if a.command=='checksums':
rows=json.loads((SCRIPT/'checksums.json').read_text())
for rel,h in rows.items():
if hashlib.sha256((SCRIPT/rel).read_bytes()).hexdigest()!=h: raise RuntimeError('script differs: '+rel)
print('Script checksums passed:',len(rows)); return
if a.command=='validate':
run('validate_release.py',(['--tensors'] if a.tensors else [])+(['--media'] if a.media else [])); return
if a.command=='preflight':
if not (ROOT/'raw').is_dir(): raise RuntimeError('Missing raw sibling')
if not all((path('models')/n).is_file() for n in ('MANO_LEFT.pkl','MANO_RIGHT.pkl')): raise RuntimeError('Configure licensed MANO files in config.json models')
subprocess.run([sys.executable,'-c','import numpy,torch,PIL,smplx'+(',cv2' if reinter else ',scipy,imageio_ffmpeg')],env=env,check=True)
subprocess.run(['ffmpeg','-version'],check=True,stdout=subprocess.DEVNULL)
import shutil
if shutil.disk_usage(ROOT).free<c['minimum_free_bytes']: raise RuntimeError('Insufficient free disk space')
print('Preflight passed'); return
if a.command=='review':
out=path('review_output')
if out.exists(): raise RuntimeError('Review output already exists; select a new review_output to preserve previous approval')
if reinter:
run('render_reinterhand_full_random.py',['--release',RELEASE,'--runtime',path('runtime'),'--output',out,'--host-label',c['partition'],'--seed',c['seed']])
else:
run('render_oakink2_full_random.py',['--release',RELEASE,'--mano-model-dir',path('models'),'--output',out,'--seed',c['seed']])
return
if a.command in ('pilot','full') and (RELEASE/'data').exists() and any((RELEASE/'data').iterdir()):
raise RuntimeError('Existing release data is protected by the handoff entry. Use a fresh dataset root for reproduction; see README for checkpoint recovery.')
if not reinter:
args=['inventory' if a.command=='inventory' else 'convert' if a.command=='pilot' else 'full','--root',ROOT]
if a.command!='inventory': args+=['--mano-model-dir',path('models'),'--workers',c['workers'],'--ffmpeg-threads','2']
if a.command=='pilot':
if not a.sequence: p.error('pilot requires --sequence')
args+=['--sequence',a.sequence]
run('preprocess_oakink2.py',args); return
if a.command=='inventory':
captures=sorted(x.parent.name for x in (ROOT/'raw/data').glob('*/frame_list.txt'))
print(json.dumps({'captures':captures})); return
if a.command=='pilot':
if not a.sequence or not a.segment: p.error('pilot requires --sequence CAPTURE --segment ACTION')
args=['--root',ROOT,'--capture',a.sequence,'--segment',a.segment]
run('preprocess_reinterhand.py',['extract-pilot',*args])
run('preprocess_reinterhand.py',['extract-background-variant',*args,'--variant','envmap_per_frame'])
run('preprocess_reinterhand.py',['convert-complete-pilot-v2',*args,'--runtime',path('runtime')])
run('preprocess_reinterhand.py',['render-expanded-review',*args,'--runtime',path('runtime')]); return
args=['run','--root',ROOT,'--runtime',path('runtime'),'--workers',c['workers']]
if c.get('captures_file'): args+=['--captures-file',SCRIPT/c['captures_file']]
run('preprocess_reinterhand_full.py',args)
if __name__=='__main__': main()