XYZNOT

Papers · arXiv 2304.02643

Segment Anything

Published cs.CVcs.AIcs.LG arXivPDF

Read with translation and AI

Summary in three lines

  1. 🎯 Segmenting unseen visual concepts and adapting to diverse downstream segmentation tasks without task-specific fine-tuning.
  2. 🔧 Introduces a promptable segmentation task, the Segment Anything Model (SAM) with an amortized real-time mask decoder, and a three-stage data engine.
  3. 📈 Trained on SA-1B (1.1B masks across 11M images), SAM transfers zero-shot to edge detection, object proposal generation, and instance segmentation, outperforming interactive baselines on 16 of 23 datasets.

Abstract

We introduce the Segment Anything (SA) project: a new task, model, and dataset for image segmentation. Using our efficient model in a data collection loop, we built the largest segmentation dataset to date (by far), with over 1 billion masks on 11M licensed and privacy respecting images. The model is designed and trained to be promptable, so it can transfer zero-shot to new image distributions and tasks. We evaluate its capabilities on numerous tasks and find that its zero-shot performance is impressive -- often competitive with or even superior to prior fully supervised results. We are releasing the Segment Anything Model (SAM) and corresponding dataset (SA-1B) of 1B masks and 11M images at https://segment-anything.com to foster research into foundation models for computer vision.

Reading guide

Problem and motivation

Foundation models pre-trained on web-scale data have revolutionized NLP and vision-language alignment (e.g., CLIP), but general computer vision lacks a foundational system capable of broad zero-shot generalization across diverse segmentation tasks. Existing datasets for image segmentation are small compared to web-scale image-text corpora, and conventional segmentation architectures are typically tied to fixed semantic classes or specialized interactive setups.

To build a vision foundation model for segmentation, the authors simultaneously address three core elements:

  1. Task: What objective allows general zero-shot transfer?
  2. Model: What architecture supports flexible prompting in real time while resolving inherent visual ambiguity?
  3. Data: How can web-scale segmentation masks be acquired when internet data lacks dense mask annotations?

Key ideas

  • Promptable Segmentation Task: The model must return a valid segmentation mask given any prompt—such as foreground/background points, bounding boxes, dense masks, or free-form text. When a prompt is ambiguous (e.g., a single point on a shirt), the model must output multiple plausible hierarchical masks (subpart, part, whole).
  • Asymmetric Amortized Architecture (SAM): A compute-heavy image encoder runs once per image to produce an embedding, while a lightweight prompt encoder and two-layer Transformer decoder evaluate prompts in on a CPU inside a web browser.
  • Flywheel Data Engine: A three-stage annotation pipeline:
    1. Assisted-manual: SAM aids annotators in a browser, dropping annotation time from 34s to 14s per mask (collecting 4.3M masks).
    2. Semi-automatic: SAM detects confident masks to guide annotators toward unannotated, less prominent objects (collecting 5.9M additional masks).
    3. Fully automatic: SAM is prompted on a uniform point grid plus zoomed-in image crops, generating the 1.1 billion masks in SA-1B.

Method

Model Architecture

SAM consists of three components:

  1. Image Encoder: An MAE pre-trained Vision Transformer (ViT-H/16 default) adapted with windowed attention and four global attention blocks, processing inputs to produce a embedding with 256 channels.
  2. Prompt Encoder:
    • Sparse prompts: Points and bounding boxes are mapped to 256-dimensional vectors using positional encodings summed with learned type embeddings. Free-form text is encoded using CLIP's text encoder.
    • Dense prompts: Input masks (at lower resolution) are downscaled via stride-2 convolutions and added element-wise to the image embedding.
  3. Mask Decoder: A two-layer modified Transformer decoder. It updates prompt tokens and image embeddings through alternating prompt self-attention and bidirectional cross-attention (tokens-to-image and image-to-tokens). The image features are upscaled via transposed convolutions, and an MLP projects the output token to produce a dynamic linear classifier applied point-wise to the upscaled features.

Ambiguity-Aware Output and Loss

A single prompt often describes multiple nested structures. SAM addresses ambiguity by predicting 3 masks simultaneously with corresponding estimated IoU scores. During training, backpropagation applies only to the minimum loss across the candidates: An auxiliary head minimizes the mean-squared-error between predicted IoU and ground truth IoU: When multiple prompts are provided, SAM outputs a single unambiguous mask using a fourth dedicated output token.


Results

  • Zero-Shot Point-to-Mask Transfer: Across 23 diverse segmentation datasets (including egocentric, underwater, aerial, and microscopy imagery), SAM outperforms RITM on 16 of 23 datasets using a single center point prompt (with deltas reaching IoU). When ambiguity is resolved via an oracle selector over SAM's 3 predictions, SAM outperforms RITM on all 23 datasets. Human quality ratings consistently rate SAM significantly higher (between 7 and 9 out of 10).
  • Zero-Shot Edge Detection (BSDS500): Evaluated zero-shot using a grid with Sobel filtering and edge NMS, SAM achieves an ODS of 0.768 and an R50 of 0.928, performing competitively with supervised models like HED (ODS 0.788, R50 0.923).
  • Zero-Shot Object Proposals (LVIS v1): SAM scores 59.3 AR@1000 without class supervision, outperforming a fully-supervised ViTDet-H baseline on medium objects (81.6 vs. 80.8), large objects (86.9 vs. 87.0), and rare categories (65.8 vs. 58.3).
  • Zero-Shot Instance Segmentation: When prompted with ViTDet bounding boxes, SAM reaches 46.5 AP on COCO and 44.7 AP on LVIS. In human evaluations, annotators consistently rate SAM masks as cleaner and higher quality than fully supervised ViTDet outputs.

Limitations and open questions

  • Fine details and extreme zoom: SAM can miss ultra-fine structures or produce small disconnected components compared to compute-heavy interactive methods that explicitly zoom into crops.
  • Full-pipeline latency: While prompt decoding is real-time (), running the heavy ViT-H image encoder is not real-time.
  • Semantic understanding: SAM yields class-agnostic masks; it does not natively provide semantic or panoptic category labels without composable exterior classifiers.
  • Text-to-mask prompting: The zero-shot CLIP-aligned text prompting pipeline remains preliminary and sensitive compared to geometric prompts.

Key terms

promptable segmentation task
A task defining the goal of outputting a valid segmentation mask given arbitrary input prompts such as points, bounding boxes, masks, or text.
SAM
Segment Anything Model; a vision model composed of a heavy ViT image encoder, a prompt encoder, and an amortized real-time lightweight mask decoder.
SA-1B
The Segment Anything 1-Billion dataset, containing over 1.1 billion automatically generated masks across 11 million high-resolution, privacy-preserving images.
data engine
The three-stage model-in-the-loop framework (assisted-manual, semi-automatic, and fully automatic) used to scale mask annotation to web scale.
ambiguity-aware modeling
A design choice where the decoder outputs 3 hierarchical masks and their predicted IoUs for a single prompt, computing training gradients only from the lowest-loss prediction.
amortized real-time inference
Computing a heavy image embedding once per image so that subsequent prompt-conditioned mask decodings execute in roughly 50ms on CPU.
zero-shot transfer
Evaluating the pre-trained promptable model on downstream tasks and unseen image distributions using prompt engineering without fine-tuning weights.
stable mask filtering
A quality filter that selects masks whose binary shapes vary negligibly when thresholding logit probability maps at versus .

Questions

How does SAM handle ambiguity when a single point can mean multiple objects?

SAM outputs three masks simultaneously (typically representing subpart, part, and whole) along with predicted IoU confidence scores. During training, it backpropagates loss only from the prediction with the lowest error.

Are the 1.1 billion masks in SA-1B manually labeled?

No, 99.1% of the masks released in SA-1B were generated fully automatically by prompting SAM on uniform point grids across 11M images, with extensive filtering for confidence and stability.

Can SAM segment an image based on text descriptions?

Yes, as an exploratory proof-of-concept. SAM was trained by feeding CLIP image embeddings of masks as prompt tokens during training, which allows text embeddings from CLIP's text encoder to prompt SAM at inference time.

Why is SAM's mask AP lower than ViTDet on COCO if humans rate SAM's masks higher?

Supervised models learn dataset-specific polygon biases, boundary smoothing artifacts, and amodal conventions present in COCO ground truth, whereas zero-shot SAM outputs crisp, modal visual boundaries that match human perception but incur IoU penalties against biased annotations.

The overview on this page was written by AI from the paper and may contain mistakes. Read the paper for the details.

Read with translation and AI