File size: 4,755 Bytes
bdd9ed1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""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()