How do I run SAM 2's video predictor to get per-object masklets for compositing plates (init_state, prompts, propagate_in_video)?
Problem. Isolating a generated subject across frames for compositing. Conditions. Python >= 3.10, torch >= 2.5.1, torchvision >= 0.20.1, CUDA toolkit matching PyTorch for the custom kernel. Method. build_sam2_video_predictor(model_cfg, checkpoint) with e.g. configs/sam2.1/sam2.1_hiera_l.yaml and sam2.1_hiera_large.pt; inside torch.inference_mode() with autocast bfloat16: state = predictor.init_state(video); predictor.add_new_points_or_box(state, prompts) returns masks for that frame; then iterate predictor.propagate_in_video(state) to get masklets for all frames. The 12/11/2024 update adds vos_optimized=True (torch.compile of the whole model) and independent per-object inference, allowing new objects to be added after tracking starts. Craft use (inference): SAM 2 output is a segmentation mask, not a soft alpha, so edges with hair, motion blur or transparency need a matting or edge-refine pass (see C3-B571-16 and 17). Failure modes. See the existing record for SAM 2's reported failur...
Structured fields
{
"citations": [
{
"url": "https://raw.githubusercontent.com/facebookresearch/sam2/main/README.md",
"note": "Video prediction; Installation; 12/11/2024 update; 12/11/2024 update; License; mask vs alpha"
}
]
}Evidence claims
- [sourced_fact] Problem. Isolating a generated subject across frames for compositing. Conditions. Python >= 3.10, torch >= 2.5.1, torchvision >= 0.20.1, CUDA toolkit matching PyTorch for the custom kernel. Method. build_sam2_video_predictor(model_cfg, checkpoint) with e.g. configs/sam2.1/sam2.1_hiera_l.yaml and sam2.1_hiera_large.pt; inside torch.inference_mode() with autocast bfloat16: state = predictor.init_state(video); predictor.add_new_points_or_box(state, prompts) returns masks for that frame; then iterate predictor.propagate_in_video(state) to get masklets for all frames. The 12/11/2024 update adds vos_optimized=True (torch.compile of the whole model) and independent per-object inference, allowing new objects to be added after tracking starts. Craft use (inference): SAM 2 output is a segmentation mask, not a soft alpha, so edges with hair, motion blur or transparency need a matting or edge-refine pass (see C3-B571-16 and 17). Failure modes. See the existing record for SAM 2's reported failures. Limitations. README gives API shape only; prompts format (points, labels, boxes) is in the notebooks, not read here. Version/date. SAM 2.1 checkpoints; README fetched 2026-10-23. · locator: Video prediction; Installation; 12/11/2024 update; 12/11/2024 update; License; mask vs alpha source
Rights
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |