Overview

SAM 2 (Segment Anything Model 2) is a promptable segmentation model from Meta’s FAIR research group, released on July 29, 2024. It extends the original Segment Anything Model from still images to video: you mark an object with a click, a box or a mask, and the model returns a pixel-accurate outline and follows that object from frame to frame. Meta presents it as a single model for both tasks, treating an image as a video with one frame.

How it works

The paper describes a simple transformer architecture with streaming memory. Video frames are processed one at a time, and a memory of earlier frames and earlier user prompts lets the model keep track of an object as it moves, changes shape or is briefly hidden. If the tracking drifts, the user can add a correction on any frame and the model propagates it through the rest of the clip.

The model was trained on SA-V, a dataset Meta collected with a “model-in-the-loop” data engine in which annotators and the model improved each other. According to the repository, SA-V holds about 51,000 videos and 643,000 spatio-temporal masks (“masklets”) and is released under CC BY 4.0. In the paper, Meta reports better video segmentation accuracy than earlier approaches with three times fewer interactions, and image segmentation that is more accurate and six times faster than the original SAM.

Sizes and versions

Checkpoints come in four sizes built on Hiera image encoders: tiny (38.9M parameters), small (46M), base plus (80.8M) and large (224.4M). On an A100 GPU, Meta measured 91.2 frames per second for the smallest SAM 2.1 checkpoint and 39.5 for the largest. Improved SAM 2.1 checkpoints followed on September 29, 2024, together with training code and the code for the web demo.

How to run it

The official GitHub repository installs with pip and needs Python 3.10 or later and PyTorch 2.5.1 or later; checkpoints can also be loaded from Hugging Face. Meta hosts an online demo, and the model checkpoints, training code and demo code are all under Apache 2.0.

Things to consider

  • It outlines objects but does not name or classify them; pair it with a detector or a vision-language model for that.
  • Long videos, crowded scenes and heavy occlusion remain hard cases.
  • Real-time video speeds assume a data-centre GPU; consumer hardware will be slower.
  • Meta has since released SAM 3, which adds segmentation from short text prompts. Other open vision models in our directory include DINOv2 and Florence-2.

Our explainer on Segment Anything explains promptable segmentation and where SAM 2 fits in Meta’s Segment Anything line.

Specifications are taken from Meta’s GitHub repository and the SAM 2 paper. Benchmark results depend on evaluation settings; see how AI benchmarks work.