
- arXiv: 2304.02643 · PDF: https://arxiv.org/pdf/2304.02643
- HTML source (ar5iv): https://ar5iv.labs.arxiv.org/html/2304.02643
- Project & demo: https://segment-anything.com
Figures are linked to their ar5iv-hosted originals. Sections 9.3–11 synthesize the paper’s later experiments and discussion, which continue beyond the truncated HTML capture; consult the official PDF for exact appendix tables and hyperparameters.
Executive summary
Segment Anything (SA) is a project — not merely a model — that ports the “foundation model” recipe from NLP to image segmentation. It is built on three tightly coupled deliverables:
- A task — promptable segmentation: return a valid mask for any prompt (point, box, mask, or text), even when the prompt is ambiguous.
- A model — SAM (Segment Anything Model): a heavyweight image encoder, a lightweight prompt encoder, and a fast mask decoder, designed so the expensive image embedding is computed once and reused across many cheap (~50 ms) prompt queries in a browser.
- A dataset — SA-1B: over 1.1 billion masks on 11 million licensed, privacy-protecting images — roughly 400× more masks than any prior segmentation dataset — collected by a data engine that loops model and annotators.
The headline result is that SAM transfers zero-shot to a wide range of segmentation tasks and image distributions via prompt engineering, frequently matching or exceeding prior fully supervised methods without any task-specific training. SAM and SA-1B were released openly (Apache 2.0 for the model) to catalyze research into vision foundation models.
Motivation: foundation models for vision
Large language models pre-trained on web-scale corpora exhibit strong zero-shot and few-shot generalization, typically accessed through prompt engineering. Their zero/few-shot behavior scales predictably with model size, dataset size, and compute, and can rival fine-tuned models.
Vision has seen analogous progress, most prominently in image–text alignment models such as CLIP and ALIGN, which use contrastive learning to produce encoders that generalize zero-shot to new visual concepts and compose with other modules (e.g., DALL·E). But much of computer vision lies beyond image–text alignment, and for many of those problems abundant training data simply does not exist. Segmentation is a prime example: there is no web-scale source of masks.
The authors set an explicit goal: build a foundation model for image segmentation — a promptable model, pre-trained on a broad dataset via a task that enables powerful generalization, so that downstream segmentation problems on new data distributions can be solved through prompt engineering. Success hinges on jointly answering three entangled questions:
- What task enables zero-shot generalization?
- What model architecture supports it?
- What data can power that task and model?
The three interconnected components
The design is deliberately circular: the task defines a pre-training objective and a prompting interface; the model must be flexible and fast enough to serve both interactive annotation and downstream prompting; and the data engine uses the model to collect data that in turn improves the model.
flowchart LR
Task["Promptable segmentation<br/>TASK"]
Model["SAM<br/>MODEL"]
Data["Data engine<br/>+ SA-1B DATA"]
Down["Zero-shot<br/>downstream tasks"]
Task -- "defines pre-training objective" --> Model
Model -- "powers annotation in the loop" --> Data
Data -- "trains and improves" --> Model
Model -- "prompt engineering" --> Down
The promptable segmentation task
Definition
Borrowing from NLP’s next-token-prediction paradigm — one objective that serves both pre-training and downstream transfer — the authors define promptable segmentation:
Given any prompt, return a valid segmentation mask.
A prompt specifies what to segment: a set of foreground/background points, a rough box, a coarse mask, free-form text, or any combination. Validity is the crucial subtlety: when a prompt is ambiguous (a single point on a shirt could indicate the shirt or the person), the output need only be a reasonable mask for at least one plausible object — much as a language model should still return a coherent response to an ambiguous query.
Pre-training
The task implies a natural pre-training algorithm adapted from interactive segmentation: for each training mask, simulate a sequence of prompts and compare the model’s predictions to ground truth across the sequence. The key departure from classic interactive segmentation is the objective — rather than aiming to eventually produce a good mask after enough user input, SAM must always produce a valid mask for any prompt, including ambiguous ones. This property is what later makes fully automatic annotation feasible.
Zero-shot transfer via prompting
Because the model can respond appropriately to any prompt, downstream tasks reduce to engineering the right prompt. For example, given a cat bounding-box detector, cat instance segmentation is solved by feeding each detected box to SAM as a prompt. This is task generalization — importantly different from multi-task systems, which perform a fixed set of tasks whose training and test tasks coincide. SAM instead acts as a composable component inside larger systems, potentially serving tasks unknown at design time.
flowchart LR
subgraph Prompts["Prompt types"]
P1["Foreground / background points"]
P2["Bounding box"]
P3["Coarse mask"]
P4["Free-form text"]
end
Prompts --> SAM["SAM<br/>(promptable segmentation)"]
SAM --> V["Valid mask(s)<br/>for at least one plausible object"]
subgraph Downstream["Downstream tasks via prompt engineering"]
D1["Edge detection"]
D2["Object proposals"]
D3["Instance segmentation<br/>(detector box → SAM)"]
D4["Text-to-mask"]
end
V --> Downstream
The Segment Anything Model (SAM)
Design constraints
Three requirements flow from the task and from the goal of real-world interactive use:
- Flexible prompts — points, boxes, masks, and text must all be accepted.
- Amortized real-time — masks must be computed fast enough for interactive prompting.
- Ambiguity-aware — a single ambiguous prompt should yield multiple valid masks.
A surprisingly simple three-part design satisfies all three.
Architecture
flowchart LR
IMG["Input image"] --> IE["Image encoder<br/>(MAE-pretrained ViT-H,<br/>adapted for high-res)"]
IE --> EMB["Image embedding<br/>(computed once per image)"]
subgraph PE["Prompt encoder"]
SPARSE["Sparse: points, box, text<br/>positional enc. + learned emb.<br/>(text via CLIP encoder)"]
DENSE["Dense: mask<br/>convolution, summed with image emb."]
end
EMB --> DEC
PE --> DEC["Mask decoder<br/>(2x modified Transformer blocks:<br/>prompt self-attn + bidirectional cross-attn)"]
DEC --> UP["Upsample + dynamic linear classifier (MLP)"]
UP --> MASKS["3 output masks<br/>+ IoU confidence per mask"]
Image encoder. An MAE-pretrained Vision Transformer (ViT), minimally adapted to process high-resolution inputs. It runs once per image; its output embedding is cached and reused for every subsequent prompt — the crux of the “amortized real-time” property.
Prompt encoder. Two families:
- Sparse prompts (points, boxes, text): points and boxes are represented by positional encodings summed with learned type-specific embeddings; free-form text uses an off-the-shelf CLIP text encoder.
- Dense prompts (masks): embedded via convolutions and summed element-wise with the image embedding.
Mask decoder. A lightweight, modified Transformer decoder that maps the image embedding, prompt embeddings, and a learned output token to a mask. Each of its two blocks applies prompt self-attention plus cross-attention in both directions (prompt→image and image→prompt), updating all embeddings. The image embedding is then upsampled, and an MLP turns the output token into a dynamic linear classifier that computes a foreground probability at every location.
Resolving ambiguity
With a single output, the model would average conflicting valid masks under ambiguity. Instead SAM predicts three masks per prompt — empirically sufficient, since nested masks are typically at most three deep (whole → part → subpart). During training, loss is backpropagated only through the minimum-loss mask (a “hindsight”/multiple-choice loss). Each mask also gets a predicted confidence score (estimated IoU) used to rank outputs.
Efficiency
Given a precomputed image embedding, the prompt encoder + mask decoder run in ~50 ms in a web browser on CPU, enabling seamless interactive prompting. The heavy ViT image encoder is the expensive part, but its cost is amortized across all prompts on that image.
Losses and training
Mask supervision combines focal loss and dice loss. Training simulates an interactive setup by randomly sampling prompts over 11 rounds per mask, so SAM integrates directly into the data engine’s annotation loop. Text prompts are handled separately (see Section 1.9.5).
The data engine
Because masks are not abundant online, the authors co-develop the model and the dataset: SAM assists annotation, and newly annotated data improves SAM. The engine has three stages of increasing automation.
flowchart TB
subgraph S1["Stage 1 — Assisted-manual"]
A1["Annotators click FG/BG points in a browser tool powered by SAM;<br/>refine with brush/eraser. No semantic constraints."]
A1 --> A2["SAM retrained 6x on new masks;<br/>encoder scaled ViT-B → ViT-H.<br/>Time/mask: 34s → 14s. ~20 → 44 masks/img."]
end
subgraph S2["Stage 2 — Semi-automatic"]
B1["Pre-fill confident masks via a generic 'object' detector<br/>trained on stage-1 masks; annotators add missed objects."]
B1 --> B2["Retrained 5x. Diversity up.<br/>44 → 72 masks/img."]
end
subgraph S3["Stage 3 — Fully automatic"]
C1["Prompt SAM with 32x32 point grid;<br/>ambiguity-aware model returns whole/part/subpart."]
C1 --> C2["Filter by predicted IoU + stability;<br/>NMS de-dupes; zoomed crops for small masks."]
end
S1 --> S2 --> S3
S3 --> OUT["11M images → 1.1B masks (SA-1B)"]
Stage 1 — Assisted-manual
Professional annotators label masks by clicking foreground/background points in a browser tool powered by SAM (using precomputed embeddings for real-time interaction), refining with pixel-precise brush/eraser tools. No semantic constraints — annotators freely label both “stuff” and “things,” labeling in order of prominence and moving on after ~30 s per mask. SAM was initially trained on public datasets, then retrained only on newly collected masks; over the stage the encoder scaled ViT-B → ViT-H and the model was retrained 6 times. Average time per mask fell from 34 s to 14 s (≈6.5× faster than COCO polygon annotation), and masks/image rose from ~20 to ~44. Yield: 4.3M masks from 120k images.
Stage 2 — Semi-automatic
Goal: increase mask diversity. A generic “object” bounding-box detector trained on stage-1 masks pre-fills confident masks; annotators then focus on the remaining, less prominent objects. The model was retrained 5 times; time/mask returned to ~34 s (harder objects), and masks/image rose 44 → 72 (including automatic masks). Added 5.9M masks in 180k images (10.2M total).
Stage 3 — Fully automatic
Now feasible because (a) enough diverse masks had been collected and (b) the model was ambiguity-aware. SAM is prompted with a 32×32 regular grid of points; each point yields masks for whole/part/subpart. Masks are filtered by predicted IoU (confidence) and stability (thresholding the probability map at 0.5±δ yields similar masks), then de-duplicated with NMS; zoomed-in crops improve small masks. Applied to all 11M images, producing 1.1B masks.
The SA-1B dataset
SA-1B = 11M licensed, privacy-protecting images + 1.1B high-quality masks.
- Images. Licensed from a provider working directly with photographers; average native resolution ~3300×4950 px. Released downsampled to 1500 px shortest side (still far larger than, e.g., COCO’s ~480×640). Faces and license plates are blurred.
- Masks. 99.1% generated fully automatically. SA-1B ships only automatic masks, justified by quality analysis.
- Mask quality. On ~500 images (~50k masks), professionals corrected the automatic masks. 94% of pairs exceed 90% IoU; 97% exceed 75% IoU — comparable to or better than reported inter-annotator consistency (85–91% IoU). Training on automatic masks alone is nearly as good as using all data-engine masks.
- Scale. 11× more images and 400× more masks than Open Images (the next largest); ~36× more masks per image; even ADE20K has 3.5× fewer masks/image.
- Mask properties. Better coverage of image corners than LVIS/ADE20K (COCO and Open Images show stronger center bias); more small/medium relative-size masks; concavity (shape-complexity) distribution similar to other datasets after controlling for size.



Figure 6: Dataset mask properties — masks per image, image-relative mask size, and mask concavity — compared across datasets.
Responsible AI analysis
The authors examine geographic/income representation and fairness across perceived attributes of people.
Geographic & income representation (Table 1). SA-1B has higher representation in Europe and Asia & Oceania and in middle-income countries than COCO/Open Images, which skew heavily to North America and high-income countries. Africa, Latin America & Caribbean, and low-income countries remain underrepresented across all datasets — but even Africa has ≥28M masks in SA-1B (10× more than the total masks of any prior dataset). Masks per image are consistent across regions/income (~94–108).
| Region | # countries | # images | # masks | SA-1B % | COCO % | Open Images % |
|---|---|---|---|---|---|---|
| Africa | 54 | 300k | 28M | 2.8% | 3.0% | 1.7% |
| Asia & Oceania | 70 | 3.9M | 423M | 36.2% | 11.4% | 14.3% |
| Europe | 47 | 5.4M | 540M | 49.8% | 34.2% | 36.2% |
| Latin America & Carib. | 42 | 380k | 36M | 3.5% | 3.1% | 5.0% |
| North America | 4 | 830k | 80M | 7.7% | 48.3% | 42.8% |
| High income | 81 | 5.8M | 598M | 54.0% | 89.1% | 87.5% |
| Middle income | 108 | 4.9M | 499M | 45.0% | 10.5% | 12.0% |
| Low income | 28 | 100k | 9.4M | 0.9% | 0.4% | 0.5% |
Fairness in segmenting people (Table 2). Using simulated interactive segmentation (1 and 3 points) on MIAP (gender presentation, age) and a proprietary skin-tone dataset (Fitzpatrick 1–6), SAM performs similarly across groups — confidence intervals overlap except older vs. middle age. Example (mIoU @ 1 point / @ 3 points): feminine 54.4 / 90.4, masculine 55.7 / 90.1; older 62.9 / 92.6; skin tones 1–6 range roughly 51–57 / 91–92. The authors caution that biases may still arise when SAM is embedded in larger systems, and note an indication of bias in clothing segmentation across perceived gender (appendix).
Zero-shot transfer experiments
Unless stated otherwise, SAM uses an MAE-pretrained ViT-H encoder and is trained on SA-1B (automatic masks only). Five tasks are evaluated; four differ substantially from the training task and are implemented purely via prompt engineering. “Zero-shot transfer” follows CLIP’s usage (evaluation on distributions/tasks not seen in training).
Single-point valid-mask segmentation
The hardest, most ambiguous prompt: one foreground point. Because ground truth rarely enumerates all valid masks, automatic mIoU is supplemented by a human study (annotators rate masks 1–10). Points are sampled from the mask “center” (distance-transform maximum); SAM reports its most confident mask by default. The main baseline is RITM, a strong interactive segmenter.
Results. SAM beats RITM on 16 of 23 datasets by automatic mIoU (by up to ~47 IoU). With an “oracle” that picks the best of SAM’s 3 masks, SAM beats RITM on all 23. In the human study, annotators consistently rate SAM’s masks substantially higher than RITM (mean ratings ~7–9); an ambiguity-unaware, single-mask ablation scores lower than full SAM but still above RITM. Notably, on datasets where SAM loses on automatic metrics (e.g., DRAM, IBD), humans still rate it higher — illustrating the unreliability of automatic single-point metrics under ambiguity. As prompts grow from 1→9 points, methods converge (SAM is not tuned for the very-high-IoU regime); with random (rather than center) point sampling, SAM’s advantage grows.
Zero-shot edge detection
Approach. A simplified auto-mask pipeline: prompt SAM with a 16×16 grid (768 masks, 3/point), NMS, then compute edges via Sobel filtering of unthresholded mask probability maps + lightweight edge NMS. SAM never saw BSDS500 images or edge labels.
Results (BSDS500). SAM produces reasonable edge maps and outperforms classic zero-shot methods (Sobel, Canny, Felzenszwalb–Huttenlocher). It trails specialized learned detectors (HED, EDETR) but is competitive given it was never trained for edges. SAM tends to predict more edges than the ground truth annotates (it segments things not labeled in BSDS).
| Method | Year | ODS | OIS | AP | R50 |
|---|---|---|---|---|---|
| HED | 2015 | .788 | .808 | .840 | .923 |
| EDETR | 2022 | .840 | .858 | .896 | .930 |
| Sobel | 1968 | .539 | – | – | – |
| Canny | 1986 | .600 | .640 | .580 | – |
| Felz–Hutt | 2004 | .610 | .640 | .560 | – |
| SAM (zero-shot) | 2023 | .768 | .786 | .794 | .928 |
Zero-shot object proposals
Approach. Run the full automatic mask generator; treat masks as object proposals. Metric: average recall (AR) on LVIS v1 (chosen for its large vocabulary). Baseline: a strong ViTDet-H detector’s proposal stage.
Results. SAM is competitive with the strong supervised baseline. It outperforms on medium/large objects and on rare/common categories, but is worse on small and frequent objects, where ViTDet — trained specifically on LVIS — can exploit dataset-specific biases SAM never learned.
Zero-shot instance segmentation
Approach. A textbook composition: feed an object detector’s boxes (ViTDet) to SAM as prompts to produce instance masks.
Results (COCO, LVIS). SAM’s mask AP is slightly below the fully supervised ViTDet on COCO. But because COCO ground-truth masks are relatively coarse, a human study rates SAM’s masks higher than ViTDet’s — SAM’s boundaries are often visibly better than the “ground truth.” On LVIS, whose masks are higher quality, the gap narrows.
flowchart LR
IMG["Image"] --> DET["Object detector<br/>(e.g., ViTDet)"]
DET --> BOX["Detected boxes"]
BOX --> SAM["SAM<br/>(box prompt)"]
IMG --> SAM
SAM --> INST["Instance masks"]
Zero-shot text-to-mask (proof of concept)
Approach. A preliminary probe of free-form-text prompting. During training, each mask is paired with its CLIP image embedding as a prompt; because CLIP aligns image and text, at inference the model can be prompted with CLIP text embeddings instead — no explicit text supervision on masks required.
Results. SAM can segment from prompts like “a wheel” or “beaver tooth grille.” When text alone is imprecise, adding a point refines the result. The authors frame this as a proof of concept, not a robust text-to-mask system.
Ablations
Studied on the 23-dataset suite (mIoU at one center point):
- Data engine stages. Cumulative data helps: training on stages 1→1+2→1+2+3 improves results. Using only automatic masks (stage 3) performs comparably to using all stages — the practical justification for SA-1B shipping automatic masks only.
- Data scaling. Scaling images from ~0.1M → 1M → full 11M improves results with diminishing returns; a large fraction of the benefit is realized well before the full dataset.
- Image-encoder scaling. ViT-B → ViT-L gives a large jump; ViT-L → ViT-H is smaller — the paper’s default ViT-H trades compute for a modest gain.
Discussion, limitations, and impact
Foundation-model framing
SAM is positioned as a promptable, composable vision foundation model. Its value lies less in any single benchmark number and more in being a reusable component: prompt engineering and composition let one model serve many tasks — including ones unanticipated at training time — analogous to how CLIP serves as the alignment module inside DALL·E.
Limitations
- Fine structure & boundaries. SAM can miss thin structures, occasionally hallucinates small disconnected components, and produces less crisp boundaries than compute-intensive methods that “zoom in.”
- Interactive high-IoU regime. Dedicated interactive segmenters can outperform SAM when many points are provided; SAM is optimized for generality, not the very-high-IoU regime.
- Real-time caveat. Only the prompt encoder + mask decoder are real-time (~50 ms). With the heavy ViT-H image encoder, overall processing is not real-time.
- Text-to-mask is preliminary. Not robust; needs better modeling.
- Domain-specific tools may still beat SAM within their domains.
- Semantic/panoptic ambiguity. It is unclear how to design simple prompts for semantic and panoptic segmentation, and “what counts as an object” is inherently ambiguous.
Impact
By releasing SAM (Apache 2.0) and SA-1B, the authors aim to make promptable segmentation a building block for larger systems and to seed further vision-foundation-model research. SAM catalyzed a large ecosystem of downstream work (medical imaging, video, annotation tooling, and follow-ups such as HQ-SAM, MobileSAM, and SAM 2).
Key takeaways for practitioners
- Amortize the encoder. Compute the image embedding once, then issue many cheap prompts — the design pattern that makes interactive use practical.
- Exploit the 3-mask output. For ambiguous prompts, use the IoU scores to pick or expose whole/part/subpart, rather than forcing a single averaged mask.
- Compose, don’t fine-tune. Many tasks (instance segmentation, proposals, edges) are solvable by prompt engineering + composition with existing detectors/encoders — no SAM retraining needed.
- Mind the caveats. Expect softer boundaries and possible stray components on fine structures; add points to disambiguate; the encoder dominates latency.
- Automatic masks are enough. SA-1B’s automatic-only masks train strong models — a template for model-in-the-loop data engines in data-scarce domains.
Glossary
- Promptable segmentation — the task of returning a valid mask for any prompt, including ambiguous ones.
- Valid mask — a reasonable mask for at least one plausible object indicated by the prompt.
- Sparse vs. dense prompts — sparse = points/boxes/text (positional + learned embeddings, text via CLIP); dense = masks (convolutional embeddings summed with the image embedding).
- Ambiguity-aware — predicting multiple (3) masks per prompt, ranked by predicted IoU; trained with a minimum-over-masks loss.
- Amortized real-time — expensive image embedding computed once and reused across many fast prompt queries (~50 ms each).
- Data engine — model-in-the-loop annotation across assisted-manual, semi-automatic, and fully-automatic stages.
- Stability — a mask is stable if thresholding its probability map at 0.5±δ yields similar masks.
- Zero-shot transfer — applying SAM to tasks/distributions unseen in training via prompt engineering (CLIP sense).
- SA-1B — the released dataset: 11M images, 1.1B automatic masks.


