Download examples/visualizer_code/source/d4rt_scripts/demo/scale4d_inference.py from facebook/SCALE4D: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/facebook/SCALE4D/resolve/main/examples/visualizer_code/source/d4rt_scripts/demo/scale4d_inference.py
- Command line
-
hf download hf://facebook/SCALE4D/examples/visualizer_code/source/d4rt_scripts/demo/scale4d_inference.py
-
curl -L -o scale4d_inference.py https://huggingface.co/facebook/SCALE4D/resolve/main/examples/visualizer_code/source/d4rt_scripts/demo/scale4d_inference.py
2.4 kB
| """Predict SCALE4D tracks from a video or a calibrated multi-view NPZ.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from evaluation.scale4d import SCALE4D | |
| from nets.scale4d import HF_REPO_ID | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| inputs = parser.add_mutually_exclusive_group(required=True) | |
| inputs.add_argument("--video", type=Path) | |
| inputs.add_argument("--input-npz", type=Path) | |
| parser.add_argument("--checkpoint", default=HF_REPO_ID) | |
| parser.add_argument("--revision", help="Hugging Face commit or revision") | |
| parser.add_argument( | |
| "--config", | |
| type=Path, | |
| help="Inference config for weights without a recorded config", | |
| ) | |
| parser.add_argument("--output", type=Path, required=True) | |
| parser.add_argument("--device", default="cuda:0") | |
| parser.add_argument("--views", type=int, choices=(1, 2, 3)) | |
| parser.add_argument("--camera", choices=("on", "off"), default="off") | |
| parser.add_argument("--grid-size", type=int, default=16) | |
| parser.add_argument("--decoder-chunk", type=int, default=512) | |
| parser.add_argument("--no-flash", action="store_true") | |
| args = parser.parse_args() | |
| if args.grid_size < 1: | |
| parser.error("--grid-size must be positive") | |
| if args.video and args.camera == "on": | |
| parser.error("Camera ON requires calibrated input through --input-npz") | |
| if args.video and args.views not in (None, 1): | |
| parser.error("--video contains one view") | |
| if args.decoder_chunk < 1: | |
| parser.error("--decoder-chunk must be positive") | |
| args.output = args.output.expanduser() | |
| if args.output.exists(): | |
| parser.error(f"Output already exists: {args.output}") | |
| torch.set_num_threads(2) | |
| tracker = SCALE4D( | |
| args.checkpoint, | |
| device=args.device, | |
| revision=args.revision, | |
| config_path=args.config, | |
| use_flash_attn=not args.no_flash, | |
| decoder_chunk=args.decoder_chunk, | |
| ) | |
| predicted = ( | |
| tracker.predict_video(args.video, grid_size=args.grid_size) | |
| if args.video | |
| else tracker.predict_npz(args.input_npz, views=args.views, camera=args.camera) | |
| ) | |
| predicted.save(args.output) | |
| print( | |
| json.dumps({"output": str(args.output), "checkpoint_step": tracker.info.step}) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |