Segment Anything (SAM) Explained: Click-to-Cut-Out AI

In short: Segment Anything (SAM) is a Meta AI model that cuts any object out of an image from a simple hint: a click, a rough box or an earlier mask. Segmentation means marking exactly which pixels belong to an object, rather than drawing a box around it. SAM was trained on SA-1B, a dataset of over 1 billion masks on 11 million images, and its lightweight design returns a mask about 50 milliseconds after each click. SAM 2 (2024) extended it to video.
What is Segment Anything, in simple words?
SAM is a "point and cut out" model: you show it what you mean, and it outlines it precisely. Click on a dog in a photo and SAM returns a mask (the exact shape of the dog, pixel by pixel), which can be used to remove the background, edit just that object or measure it.
It was introduced in the paper Segment Anything, submitted on 5 April 2023 by Alexander Kirillov, Eric Mintun, Nikhila Ravi and colleagues at Meta AI. The paper reframed segmentation as a promptable task: give the model a hint, and it returns a mask. For where segmentation sits among other vision tasks, see computer vision explained.
What can you prompt SAM with?
SAM accepts points, boxes and masks as prompts; text was explored in the paper only as a proof of concept.
- Points: a click on the object, optionally with extra clicks marking background to leave out.
- Boxes: a rough rectangle around the object.
- Masks: a coarse earlier mask to refine.
- Text: tested in the paper as a proof of concept rather than a released feature.
A single click is often ambiguous: a click on a shirt could mean the shirt, the person wearing it, or a pocket. SAM handles this by returning three candidate masks at different levels of detail, each with a predicted quality score, rather than guessing one.
How does SAM work?
SAM has three parts, and splitting them is what makes it fast enough to use interactively.
- Image encoder - a large Vision Transformer, pre-trained with masked autoencoding. It runs once per image and produces an embedding - a compact numerical summary of the image.
- Prompt encoder - turns the clicks, boxes or masks into embeddings.
- Mask decoder - a lightweight transformer that combines the image embedding and the prompt embeddings into masks.
The expensive encoder runs once; after that, each new prompt only runs the small decoder, which the paper reports takes about 50 milliseconds in a web browser. That is what makes click-see-click-again use possible.
What is the SA-1B dataset?
SA-1B is the dataset Meta built alongside SAM: "over 1 billion masks on 11M licensed and privacy respecting images". By the authors' account it has far more masks than any earlier segmentation dataset. It was built with a three-stage "data engine" in which the model and the data improved each other:
- Assisted-manual - human annotators drew masks using an early SAM as an interactive tool.
- Semi-automatic - SAM proposed masks for objects it was confident about, and annotators labelled what it missed.
- Fully automatic - SAM was prompted with a regular grid of points on each image and generated masks with no annotator involved. Nearly all of SA-1B's masks come from this stage.
How well does SAM work?
The authors tested SAM zero-shot, on datasets it was not trained for, across 23 segmentation datasets. They report its masks from a single click were often competitive with, or better than, earlier fully supervised results on those datasets.
What is SAM 2?
SAM 2 extends the same click-to-segment approach from images to video. SAM 2: Segment Anything in Images and Videos, first submitted on 1 August 2024, adds a streaming memory, so an object selected in one frame can be tracked through later frames in real time. The paper reports that on video it reaches better accuracy than earlier approaches while needing 3× fewer user interactions, and that on images it is more accurate than the original SAM and 6× faster. Meta released the model, training code, a demo and a new video segmentation dataset alongside it.
What is SAM used for?
SAM is mostly used as a building block inside other tools.
- Labelling data: drawing masks for training other vision models far faster than by hand.
- Image editing: selecting an object to remove, recolour or cut out.
- Video editing and tracking: following an object across frames, with SAM 2.
- Pipelines: producing precise masks that are handed on to another model.
Words to know
- Segmentation: labelling exactly which pixels belong to each object.
- Mask: the pixel-by-pixel outline of one object.
- Prompt: the hint given to SAM: a click, a box or a mask.
- Promptable: a model that changes its output based on a prompt.
- Image encoder: the large part of SAM that summarises an image once.
- Mask decoder: the small, fast part that turns prompts into masks.
- Zero-shot: working on data the model was not trained on.
- SA-1B: Meta's dataset of over 1 billion masks on 11 million images.
Related guides
Frequently asked questions
What is Segment Anything (SAM)?+
Segment Anything is an image segmentation model from Meta AI, introduced in April 2023, that outlines any object in an image from a prompt such as a click, a box or a rough mask. It returns the object's exact pixel outline, called a mask.
What does SAM stand for in AI?+
SAM stands for Segment Anything Model. It was introduced in the paper "Segment Anything" by Alexander Kirillov, Eric Mintun, Nikhila Ravi and colleagues at Meta AI.
How big is the SA-1B dataset?+
SA-1B contains over 1 billion masks on 11 million licensed and privacy-respecting images. Nearly all of its masks were generated automatically by SAM itself, in the final stage of the data engine Meta used to build it.
Why does SAM return three masks?+
Because a single click can be ambiguous, for example meaning a shirt, the person wearing it or a pocket. SAM returns three candidate masks at different levels of detail, each with a predicted quality score.
How fast is SAM?+
The image encoder runs once per image. After that, the paper reports the mask decoder produces a mask for each new prompt in about 50 milliseconds in a web browser, which makes interactive use possible.
What is the difference between SAM and SAM 2?+
SAM works on single images. SAM 2, released in 2024, extends it to video with a streaming memory that tracks a selected object through later frames. Its paper reports it is also more accurate than SAM on images and 6 times faster.
Enjoyed this? Get more in your inbox.
Up to ten of the week's AI news stories, by email once a week.