7e4ef6f98b
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
45 lines
2.1 KiB
Python
45 lines
2.1 KiB
Python
"""Resume the requested egocentric video inference with existing local models."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import time
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUT = ROOT / 'output/15886123_handflow'
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
env = os.environ.copy()
|
|
env.update(PYTHONPATH=str(ROOT), LD_LIBRARY_PATH='', OMP_NUM_THREADS='4',
|
|
MKL_NUM_THREADS='4', OPENBLAS_NUM_THREADS='4',
|
|
TORCH_HOME=str(ROOT / '.torch_cache'), HF_HOME=str(ROOT / '.hf_cache'),
|
|
HF_HUB_OFFLINE='1', TRANSFORMERS_OFFLINE='1',
|
|
TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD='1', PYTHONUNBUFFERED='1',
|
|
VIPE_PYTHON=str(ROOT / '.venv/bin/python'),
|
|
HAMER_CKPT=str(ROOT / 'third_party/hamer/_DATA/hamer_ckpts/checkpoints/hamer.ckpt'),
|
|
DETECTOR_CKPT=str(ROOT / 'weights/detector.pt'),
|
|
MANO_ROOT=str(ROOT / 'third_party/hamer/_DATA/data/mano'),
|
|
HANDFLOW_NORMALIZATION_STATS=str(ROOT / 'weights/normalization_stats.npz'))
|
|
cmd = [str(ROOT / '.venv/bin/python'), '-u', 'scripts/demo.py',
|
|
'--input', '/home/timessage/下载/15886123.mp4',
|
|
'--fm_ckpt', str(ROOT / 'weights/handflow_denoiser.pt'),
|
|
'--intrinsics', 'auto', '--side', 'right', '--rotation_smooth_window', '5',
|
|
'--output_dir', str(OUT), '--save_npz', str(OUT / 'handflow_results.npz')]
|
|
|
|
def status(stage, **extra):
|
|
(OUT / 'status.json').write_text(json.dumps(dict(stage=stage, time=time.strftime('%Y-%m-%d %H:%M:%S'), **extra), indent=2))
|
|
print(stage, flush=True)
|
|
|
|
try:
|
|
for attempt in range(2):
|
|
if (OUT / 'handflow_results.npz').exists():
|
|
break
|
|
status('INFERENCE', pass_index=attempt + 1, command=cmd)
|
|
with (OUT / f'inference_pass_{attempt + 1}.log').open('a') as log:
|
|
subprocess.run(cmd, cwd=ROOT, env=env, stdout=log, stderr=subprocess.STDOUT, check=True)
|
|
if not (OUT / 'handflow_results.npz').exists():
|
|
raise RuntimeError('Inference exited without final arrays after cache restart')
|
|
status('INFERENCE_FINISHED_PENDING_VALIDATION')
|
|
except Exception as exc:
|
|
status('FAILED', error=str(exc))
|
|
raise
|