Images and video · 2024
Meta SAM 2: Segment Anything in Images and Video Click an object once and SAM 2 follows it through the whole clip. Here is how it works, what SAM 2.1 changed, and when to choose SAM 3 instead.
At a glance
SAM 2 in six facts
Is SAM 2 still the latest? SAM 2.1 is the latest SAM 2 release. Meta has since released SAM 3 and the current SAM 3.1, which add text prompts and build their video tracker on SAM 2’s design. SAM 2 is still a strong, lighter choice for click-based video tracking.
Overview
What is Meta SAM 2?
Meta SAM 2 (Segment Anything Model 2) is a promptable segmentation model for both images and video. In a photo it works like the original SAM. In a video, you prompt an object once and SAM 2 keeps its mask on it, frame after frame.
What goes in, and what comes out
- In: an image or a video. SAM 2 treats a photo as a video with a single frame, so one model handles both.
- In: a visual prompt. Clicks, a box or a mask on any frame.
- Out: a “masklet”. A mask for the object on every frame, with one ID, so you can follow it through the clip.
The big step from SAM 1: SAM 1 only saw single images. SAM 2 adds memory, so it remembers what the object looked like in earlier frames. See our video segmentation guide.
Architecture
How SAM 2 Works: Streaming Memory
SAM 2 reads a video one frame at a time, like a stream. Before predicting each mask, it looks back at a memory of earlier frames. That is what lets it keep track of an object as it moves, turns or is briefly hidden.
- 1Image encoderTurns the current frame into features, once per frame.
- 2Memory attentionCompares the current frame with the memory bank before predicting a mask.
- 3Mask decoderPredicts the mask, plus an occlusion check that says whether the object is visible in this frame at all.
- 4Memory encoder and bankTurns each new prediction into a memory and stores it with memories from earlier and prompted frames.
Because frames are processed one by one, SAM 2 can work on long videos and live streams without loading the whole clip at once.
Prompts and corrections
Prompt Once, Correct Anywhere
SAM 2 uses the same visual prompts as SAM 1: points, boxes and masks. The difference is where you can use them: on any frame, and as many times as you need.
- Points. Positive clicks on the object, negative clicks on what to leave out.
- Boxes. A rough rectangle around the object on one frame.
- Masks. An existing mask, for example from another tool, to refine and follow.
- Corrections on any frame. If the track drifts, click again on that frame and SAM 2 updates the frames after it.
- Several objects. Give each object its own ID and track them together.
SAM 2 does not understand text. Typing “all red cars” needs SAM 3. More in our prompt guide.
Occlusion
When Objects Disappear and Come Back
Real video is messy: people walk behind things, cars leave the frame. SAM 2 has a dedicated check for this, so it can say “not visible here” instead of guessing a wrong mask.
- Occlusion check. For each frame, SAM 2 predicts whether the object is present at all.
- Memory bridges the gap. When the object returns, the memory of earlier frames helps re-find it with the same ID.
- Better in SAM 2.1. Meta says the 2.1 checkpoints improved handling of occlusions and of visually similar objects.
Very long occlusions or crowded scenes can still break a track. See tracking loses objects.
Training data
The SA-V Dataset
To teach SAM 2 about motion, Meta built SA-V (Segment Anything Video), a large set of real-world videos with objects outlined over time.
- About 51,000 videos of real-world scenes, filmed in 47 countries.
- More than 600,000 masklets. A masklet is one object’s mask followed through a video.
- Whole objects and parts, including objects that get hidden, disappear and reappear.
- Made with a data engine. SAM 2 itself helped annotators, which Meta says was 8.4 times faster than annotating each frame with SAM.
SA-V is released under the CC BY 4.0 licence.
Model sizes
SAM 2.1 Checkpoints: Tiny, Small, Base+ and Large
SAM 2 comes in four sizes. The SAM 2.1 versions, released on 29 September 2024, replace the original July checkpoints and match or beat them on every video benchmark in Meta’s table.
| Checkpoint | Parameters | Speed (FPS) | SA-V test (J&F) | MOSE val (J&F) | LVOS v2 (J&F) |
|---|---|---|---|---|---|
sam2.1_hiera_tiny | 38.9M | 91.2 | 76.5 | 71.8 | 77.3 |
sam2.1_hiera_small | 46M | 84.8 | 76.6 | 73.5 | 78.3 |
sam2.1_hiera_base_plus | 80.8M | 64.1 | 78.2 | 73.7 | 78.2 |
sam2.1_hiera_large Best | 224.4M | 39.5 | 79.5 | 74.6 | 80.6 |
Quick rule: start with base+ for a good balance, use large when accuracy matters most, and tiny or small for speed or smaller GPUs. Upgrading from the July 2024 checkpoints? You need the latest code from the repository.
Performance
Speed and Accuracy
Meta’s headline results for SAM 2, compared with earlier methods and with the original SAM.
SAM 2 also scores higher than SAM 1 on that image benchmark, and performs strongly on standard video benchmarks such as DAVIS, MOSE, LVOS and YouTube-VOS. Real speed on your machine depends on GPU, resolution and checkpoint size.
Use cases
What People Use SAM 2 For
Video editing
Rotoscope a person, car or product once, then grade, blur or add effects to just that subject.
Sports and broadcast
Click players or the ball on a key frame and follow them for highlights, heat maps and overlays.
Traffic and monitoring
Track vehicles, people and bikes in camera feeds to count them or measure how long they stay.
Video data labelling
Label a few frames and let SAM 2 fill in the rest, then correct what it misses.
Robotics
Keep a stable mask on an object a robot is reaching for, even as the camera moves.
Science and medicine
Follow cells, animals or structures through microscope or ultrasound video, often after fine-tuning.
More examples on our use cases page.
Strengths and limits
Strengths and Limitations of SAM 2
Strengths
- One model for images and video.
- Prompt once, track the whole clip, with corrections on any frame.
- Handles occlusion with a dedicated visibility check.
- Fast: about 44 FPS, and faster than SAM 1 on images.
- Four sizes from 38.9M to 224.4M parameters.
- Open: Apache 2.0 code and weights, CC BY 4.0 dataset, and released training code.
Limitations (as Meta lists them)
- Can lose track after big viewpoint changes, long occlusions, in crowded scenes or long videos.
- Can confuse look-alikes when several similar objects are close together.
- Slower with many objects, because each object is processed separately.
- Fine detail and fast motion can produce missed details or jittery masks.
- No text prompts. You must click, box or mask.
Several of these are what SAM 3.1 targets, for example faster multi-object tracking. See also slow video tracking.
How to use
How to Use Meta SAM 2
Try it in your browser with no setup, or run the open-source code on your own GPU.
Without code
- 1Open a playgroundUpload an image or a short video in our Playground, or use Meta’s own SAM 2 demo.
- 2Click the objectAdd clicks until the mask on the first frame looks right.
- 3Track and fixLet it run through the clip, then click again on any frame that drifts.
- 4ExportDownload the masks or the cut-out video. See how to export masks.
With code: install
Requires Python 3.10 or later, PyTorch 2.5.1 or later and TorchVision 0.20.1 or later, on a CUDA GPU. On Windows, Meta recommends WSL with Ubuntu.
git clone https://github.com/facebookresearch/sam2.git && cd sam2
pip install -e .
cd checkpoints && ./download_ckpts.sh && cd ..For single images, use SAM2ImagePredictor, which works much like SAM 1’s predictor. Models can also be loaded straight from Hugging Face with from_pretrained.
With code: track an object in a video
import numpy as np, torch
from sam2.build_sam import build_sam2_video_predictor
predictor = build_sam2_video_predictor(
"configs/sam2.1/sam2.1_hiera_l.yaml",
"./checkpoints/sam2.1_hiera_large.pt",
)
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
# 1. Load the video (a folder of JPEG frames)
state = predictor.init_state(video_path="my_video_frames/")
# 2. Click once on frame 0 to start tracking object 1
predictor.add_new_points_or_box(
inference_state=state, frame_idx=0, obj_id=1,
points=np.array([[300, 200]], dtype=np.float32),
labels=np.array([1], dtype=np.int32), # 1 = include
)
# 3. Follow it through the rest of the video
for frame_idx, obj_ids, mask_logits in predictor.propagate_in_video(state):
masks = (mask_logits > 0.0).cpu().numpy()Based on the official sam2 repository. SAM 2 is also available in tools such as Ultralytics and Roboflow. For a full walkthrough, see the Python tutorial.
Comparison
SAM 2 vs SAM 1 vs SAM 3: Which Should You Use?
SAM 2 sits in the middle of the family: it added video to SAM 1, and SAM 3 later added text and concept prompts on top of it.
| Model | Works on | Prompts | Best for |
|---|---|---|---|
| SAM 1 | Images | Points, boxes, masks | Click-based cut-outs in photos |
| SAM 2 / 2.1 | Images, video | Points, boxes, masks | Tracking the objects you click |
| SAM 3 | Images, video | Text, exemplars, points, boxes, masks | Finding every instance of a concept |
| SAM 3.1 | Images, video | Same as SAM 3 | New projects, many objects in video |
SAM 2 or SAM 3? SAM 2 is “track this object I clicked”. SAM 3 is “find every X and follow them”. If people will click what to track, SAM 2 is lighter and has the more permissive Apache 2.0 licence. If you want to describe objects in words, choose SAM 3.
Detailed comparisons: SAM 3 vs SAM 2 · SAM 3 vs SAM 3.1 · alternatives
Quick decision
Pick the Right Model in 10 Seconds
Questions
SAM 2 FAQ
What is Meta SAM 2?
Meta SAM 2 (Segment Anything Model 2) is Meta’s second Segment Anything model. It segments objects in images and video from clicks, boxes or masks, and in video it keeps following the object from frame to frame.
When was SAM 2 released?
Meta released SAM 2 on 29 July 2024. Improved SAM 2.1 checkpoints, along with training code and a web demo, followed at the end of September 2024.
What is the difference between SAM 2 and SAM 2.1?
SAM 2.1 is an updated set of checkpoints using the same approach. Meta says it performs better on visually similar objects and on occlusions. Use SAM 2.1 checkpoints if you choose SAM 2.
Can SAM 2 understand text prompts?
No. SAM 2 uses visual prompts only: points, boxes and masks. To find objects by typing a description, use SAM 3 or SAM 3.1.
How fast is SAM 2?
Meta reports about 44 frames per second, and six times faster than the original SAM on images. Repository benchmarks on an A100 GPU range from about 39 FPS for the large model to about 91 FPS for the tiny one.
Is SAM 2 free for commercial use?
The SAM 2 model weights and code are released under Apache 2.0, and the SA-V dataset under CC BY 4.0. This is a summary, not legal advice, so read the licences before you ship a product.
Should I use SAM 2 or SAM 3?
Use SAM 2 if people will click the objects to track and you want a lighter model with a permissive Apache 2.0 licence. Use SAM 3 or SAM 3.1 if you want to type what to find and get every match.
Keep reading
Sources
- Meta AI blog: Introducing SAM 2 (release, speed, SA-V, limitations, licences)
- facebookresearch/sam2 on GitHub (checkpoints, benchmarks, requirements, code)
- Ravi et al., “SAM 2: Segment Anything in Images and Videos”, 2024
- Meta AI blog: SAM 3 and SAM 3.1