Segment Anything Model (SAM) – The Complete Guide

Subscribe

Segment Anything Model (SAM) – The Complete Guide

A guide to the Segment Anything Model (SAM): its architecture, promptable segmentation, data engine, and role in agentic computer vision.
SAM

Subscribe to the viso blog

Stay connected with viso.ai and receive new blog posts straight to your inbox.
Subscribe

The Segment Anything Model (SAM), released by Meta’s FAIR lab in April 2023, marked a turning point in computer vision. Rather than training a separate network for every segmentation task, the promptable model SAM learned to isolate almost any object in almost any image on demand. Two major follow-up releases later, the Segment Anything family has become one of the clearest demonstrations of how foundation models are reshaping visual understanding, and its segmentation capabilities now sit inside a wide range of production pipelines.

This guide covers the Segment Anything model architecture, the data engine that trained it, the applications it unlocks, and where promptable segmentation fits into agentic computer vision systems.

Segment Anything Model example application for promptable segmentation tasks
Promptable computer vision removes the need to retrain a model for every new object class, which is why industrial teams increasingly use it as the first step in image annotation workflows.

What Promptable Segmentation Changed

Before SAM, most segmentation systems were models designed for a fixed label set. A network trained to find pallets could not find pipework, and extending it meant collecting new data, annotating it, and retraining. That cost is the reason so many vision projects stall at the pilot stage.

Segment Anything reframed the problem. Its creators borrowed the prompting idea from natural language processing, where a single pre-trained model answers many downstream questions without task-specific training. SAM accepts a prompt describing what the user wants segmented, then returns a mask. Because the model was trained on an enormous and varied dataset, it generalizes to unfamiliar imagery through zero-shot transfer.

The prompts it accepts are deliberately simple:

  • Points: a single click on the foreground, or a mix of foreground and background clicks to resolve ambiguity.
  • Bounding boxes: a rough rectangle, which makes SAM easy to chain behind an existing object detection model.
  • Coarse masks: a low-quality mask that SAM refines into clean contours.
  • Everything mode: a fully automatic pass that segments every distinguishable region in the frame without any human input.

SAM does not classify what it finds. It produces high quality masks and leaves naming to a downstream classifier, detector, or language model, which is precisely what makes it so easy to compose into larger systems.

Computer Vision Builder

Bring a new AI vision application to life.

Turn ideas into computer vision apps — no coding needed.

Computer Vision at Meta AI: A Brief History

Meta’s AI research lab, founded in 2013 as Facebook AI Research and now known as FAIR, has shaped much of the modern vision stack. PyTorch gave researchers a flexible training framework, Detectron standardized detection baselines, and the Segment Anything project extended that lineage into general-purpose image segmentation. Each of these releases was open source, which is a large part of why SAM spread through the research community within weeks of publication.

The Segment Anything Model Architecture

The segment anything model architecture separates heavy visual processing from lightweight, interactive decoding. That split is what allows real-time use in a browser after a single expensive pass over the image.

Image Encoder

The image encoder is a Vision Transformer pre-trained with a masked autoencoding objective. It converts the input picture into a dense grid of image embeddings that capture texture, structure, and object boundaries. This is the expensive part of the pipeline, and it runs only once per image. Every subsequent prompt reuses the same image embeddings, which is why a user can click through dozens of objects without waiting.

Prompt Encoder

The prompt encoder turns user input into prompt embeddings the decoder can consume. Sparse prompts such as points and bounding boxes become positional encodings combined with learned type indicators. Dense prompts such as coarse masks are embedded convolutionally and added directly to the image embeddings. Handling both in one place is what gives SAM its flexibility across interfaces.

Mask Decoder

The mask decoder is a lightweight transformer that attends between image embeddings and prompt embeddings, then upsamples the result into a mask. It predicts several candidate masks for a single ambiguous prompt, along with an estimated quality score for each. A click on a person’s shirt might reasonably mean the shirt, the torso, or the whole person, so the model returns all three and lets the application choose.

Component Role Cost Profile
Image encoder Produces image embeddings from the raw frame Heavy, once per image
Prompt encoder Converts points, boxes, and masks into prompt embeddings Negligible
Mask decoder Fuses both embedding streams into ranked masks Milliseconds per prompt

The Technical Foundations Behind Model SAM

SAM did not appear from nowhere. It assembles several well-established ideas into one system.

Transformers and Convolutional Feature Extraction

Transformer attention lets the encoder relate distant parts of a scene, which matters for objects split by occlusion. Convolutional layers still handle local feature extraction inside the mask decoder’s upsampling path, so the architecture inherits the strengths of convolutional neural networks alongside global attention.

Language Grounding Through CLIP

The original SAM had no text interface of its own, but researchers quickly paired it with CLIP and other vision-language models to add one. A text encoder proposes regions, SAM refines them into masks, and the combined system responds to phrases rather than clicks. This pattern is now standard practice in open-vocabulary segmentation.

Transfer Learning and Fine-Tuning

Because the encoder learned general visual structure, transfer learning works unusually well. Teams working with medical scans, satellite imagery, or thermal cameras typically freeze the encoder and apply fine-tuning to the decoder using a few hundred labeled examples. The result is domain accuracy without the cost of training from scratch, and evaluation still comes down to familiar metrics such as precision and recall.

Inside the SA-1B Data Engine

SAM’s real advantage is its training data. The SA-1B dataset contains more than 1.1 billion masks across 11 million licensed, privacy-respecting images, making it far larger than any segmentation dataset that preceded it. Meta built it with a three-stage data engine in which the model and the annotators improved each other:

  1. Assisted manual. Professional annotators labeled objects with help from an early SAM checkpoint, correcting its mistakes as they worked.
  2. Semi-automatic. The model pre-filled confident masks, and annotators concentrated on the objects it missed, which pushed mask diversity upward.
  3. Fully automatic. The mature model generated masks on its own, with filtering to discard low-confidence predictions and keep only high-quality output.
Red bird in water with surrounding greenery processed with Segment Anything Model (SAM)
Training data breadth determines how well a segmentation model transfers to unfamiliar sites, lighting, and camera angles, a factor worth checking before any deployment.

That loop is the mechanism behind the model’s generality, and it has since been copied widely. Meta also released the dataset and weights publicly, so the research paper, the checkpoints, and the annotations can all be inspected and reproduced.

Segment Anything Model Applications

SAM is most valuable where labeling cost or object variety has been the bottleneck:

  • Accelerated annotation. A single click replaces minutes of polygon drawing, which shortens the path from raw footage to a trained model.
  • Industrial inspection. Mask boundaries give precise area and shape measurements for defect detection across manufacturing lines.
  • Medical imaging research. Organ and lesion delineation in healthcare settings, usually after domain-specific fine-tuning.
  • Remote sensing. Land cover mapping, crop boundary extraction, and infrastructure surveys from satellite imagery.
  • Content creation. Rotoscoping, background replacement, and compositing without frame-by-frame masking.
Segmentation applied to road surface assessment for infrastructure monitoring.
Pixel-level masks support measurement rather than counting alone, which is why segmentation is often chosen over detection for condition and quality assessment work.

From SAM to SAM 2 and SAM 3

The Segment Anything line has advanced twice since 2023. SAM 2, released in July 2024, added video by introducing a streaming memory module that carries object identity across frames, effectively merging segmentation with object tracking.

SAM 3, released on November 19, 2025, went further with promptable concept segmentation: given a short noun phrase or an image exemplar, it returns masks and stable identities for every matching instance at once, where earlier versions handled one object per prompt. Meta shipped it alongside the SA-Co benchmark, public checkpoints, and fine-tuning code, plus a companion SAM 3D suite for single-image reconstruction.

The practical consequence is that a text phrase such as “unattended pallet” can now drive segmentation directly, without a bespoke detector in front of it. Meta’s SAM 3 announcement documents the prompt modalities and benchmark results in detail, and the reference implementation is available for inspection.

Where Segment Anything Fits in Agentic Computer Vision

Agentic systems plan, act, and verify rather than simply reporting predictions. Segmentation is one of the tools such a system reaches for, and SAM’s promptable interface makes it unusually easy to call.

Consider an agent monitoring a warehouse aisle. A detector flags a possible obstruction and passes bounding boxes to SAM, which returns exact masks. The agent measures the blocked area, compares it against a clearance rule, checks whether the obstruction has persisted across several minutes of footage, and only then raises an alert with visual evidence attached. Each step is a tool call, and the segmentation step needed no site-specific training to work.

Two constraints shape how this runs in practice. First, encoder inference is expensive, so most deployments distill or quantize the model and push it toward edge computing hardware to avoid streaming video to a data center. Second, systems that act on people or workplaces need an audit trail, which brings obligations under frameworks such as the EU AI Act into scope from the design stage rather than after rollout.

Limitations Worth Planning For

SAM is strong at boundaries and weak at meaning. It will happily segment an object it cannot name, and it can miss thin structures such as cables or wire mesh. It also has no notion of what matters in a scene, so the surrounding computer vision tasks still carry the semantic load. Treat it as an excellent component rather than a complete solution.

FAQs

The Segment Anything Model (SAM) is a foundation model for image segmentation from Meta AI. It takes an image plus a prompt such as a point, a box, or a coarse mask, and returns pixel-accurate masks for the indicated object without task-specific training.

The original release handled still images only. SAM 2 introduced memory across frames, so it can segment and track objects through video, and SAM 3 extends that to every instance matching a text prompt.

Code, weights, and datasets have been published for each release. SAM 1 code was Apache 2.0 licensed, while SAM 3 ships under Meta’s custom SAM License, so commercial teams should read the current license terms before shipping.

SA-1B contains over 1.1 billion masks generated from 11 million images, sourced across a wide geographic distribution to limit regional bias.

No. SAM produces masks but not labels, so detectors and classifiers remain necessary. The two are usually combined, with a detector supplying bounding boxes and SAM refining them into precise masks.

Often not for everyday objects. Specialized domains such as radiology, microscopy, or infrared imaging generally benefit from decoder fine tuning on a few hundred annotated examples.