SAM 2
Meta's open-source foundation model and code for promptable visual segmentation and tracking in images and videos.
At a Glance
SAM 2 model checkpoints, demo code and training code are licensed under Apache 2.0 and are free to use, modify and distribute.
Engagement
Available On
Alternatives
Listed Nov 2026
About SAM 2
SAM 2 (Segment Anything Model 2) comes from AI at Meta, FAIR. The repository provides inference code, downloadable model checkpoints, example notebooks, training code, and a web demo for promptable segmentation in images and videos. It is released under the Apache 2.0 license.
What It Is
SAM 2 is a foundation model for promptable visual segmentation. It extends the original SAM to video by treating an image as a video with a single frame. The model uses a transformer architecture with streaming memory for real-time video processing. The repository also links the SA-V video segmentation dataset, which the authors collected with a model-in-the-loop data engine.
How It Works
Users install the Python package, download a checkpoint (SAM 2.1 tiny, small, base plus, or large), and run it through Python APIs.
- Images:
SAM2ImagePredictoraccepts prompts and returns masks. Automatic mask generation is also supported. - Videos: the video predictor takes click or box prompts, refines them, and propagates masklets through the video. It can track multiple objects and keeps an inference state for each video.
- Hugging Face: models can be loaded from Hugging Face.
Training, Demo, and Recent Updates
The repository includes code to train or fine-tune SAM 2 on custom image and video datasets. It also includes frontend and backend code for a locally deployable web demo. The December 2024 update added torch.compile support for the full model on videos, enabled with vos_optimized=True, and a reworked SAM2VideoPredictor that supports independent per-object inference and adding objects after tracking starts. The SAM 2.1 release in September 2024 brought improved checkpoints.
Setup Requirements
The code requires Python 3.10 or later, torch 2.5.1 or later, and torchvision 0.20.1 or later. It targets GPU machines, and installation compiles a custom CUDA kernel with nvcc. The README recommends WSL with Ubuntu on Windows.
Community Discussions
Be the first to start a conversation about SAM 2
Share your experience with SAM 2, ask questions, or help others learn from your insights.
Pricing
Open Source (Apache 2.0)
SAM 2 model checkpoints, demo code and training code are licensed under Apache 2.0 and are free to use, modify and distribute.
- SAM 2 model checkpoints under Apache 2.0
- SAM 2 demo code (front-end and back-end) under Apache 2.0
- SAM 2 training code under Apache 2.0
- Inter Font and Noto Color Emoji in demo code are under SIL Open Font License 1.1
- Third-party cc_torch-adapted code has its own license (LICENSE_cctorch)
Capabilities
Key Features
- Promptable segmentation in images and videos
- Click and box prompts with refinement
- Multi-object video tracking with masklets
- Automatic mask generation on images
- SAM 2.1 checkpoints in tiny, small, base plus, and large sizes
- Training and fine-tuning code
- Locally deployable web demo
- Hugging Face model loading
- torch.compile full-model optimization for video inference
