File size: 2,399 Bytes
9c890d3 | 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 | """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()
|