sam-vit-base

The Segment Anything Model (SAM) – ViT‑Base is a prompt‑able, foundation‑level vision model that generates high‑quality object masks from a variety of user‑provided cues. Unlike traditional semantic

facebook 274K downloads apache-2.0 Mask Generation
Frameworkstransformerspytorchtfsafetensors
Tagssammask-generationvision
Downloads
274K
License
apache-2.0
Pipeline
Mask Generation
Author
facebook

Run sam-vit-base locally on a Q4KM hard drive

Accelerate your deployment with Q4KM hard drives pre‑loaded with the facebook/sam-vit-base model. These plug‑and‑play drives eliminate download time, ensure optimal storage layout, and come with a...

Shop Q4KM Drives

Technical Overview

The Segment Anything Model (SAM) – ViT‑Base is a prompt‑able, foundation‑level vision model that generates high‑quality object masks from a variety of user‑provided cues. Unlike traditional semantic segmentation networks that predict a fixed set of classes, SAM treats segmentation as a conditional generation problem: given an image and a prompt (point, bounding box, or mask), it predicts a binary mask that aligns with the indicated object. The model is built on a Vision Transformer (ViT‑B) backbone and is part of the larger “Segment Anything” project that released a 1‑billion‑mask dataset (SA‑1B) to train a truly zero‑shot capable segmenter.

Key features and capabilities

  • Promptable segmentation – Accepts points, boxes, or rough masks as input.
  • Zero‑shot generalisation – Works out‑of‑the‑box on unseen image domains without fine‑tuning.
  • High‑resolution mask output – Produces masks at the original image resolution via a dedicated mask decoder.
  • Fast inference – The ViT‑Base encoder balances accuracy and speed, making it suitable for real‑time applications on modern GPUs.
  • Multi‑modal compatibility – Implemented in both PyTorch and TensorFlow, with safetensors support for efficient loading.

Architecture highlights

  • Vision Encoder (ViT‑B) – 12‑layer transformer that tokenises the image into 16×16 patches, adds relative positional embeddings, and outputs a dense image embedding.
  • Prompt Encoder – Encodes sparse prompts (points, boxes) into a set of prompt embeddings that are concatenated with the image embedding.
  • Mask Decoder – A two‑way transformer that performs cross‑attention between image and prompt embeddings, refining the representation before mask prediction.
  • Neck (Mask Head) – A lightweight convolutional head that upsamples the decoder output and produces the final binary mask and an IoU quality score.

Intended use cases

  • Interactive image editing (e.g., Photoshop‑style “magic wand”).
  • Data annotation acceleration for computer‑vision pipelines.
  • Robotics perception where a user can quickly highlight objects of interest.
  • Medical imaging where clinicians can point to a region and obtain a precise mask.
  • Content‑aware video editing and AR/VR scene understanding.

Benchmark Performance

For a segmentation model, the most informative benchmarks are mask quality (mean IoU, Dice coefficient) and prompt efficiency (how many prompts are needed to achieve a given recall). The original SAM paper evaluated the ViT‑Base variant on several public datasets, including COCO, ADE20K, and the SA‑1B test split.

  • COCO‑Mask – 0.73 mean IoU (zero‑shot) with a single point prompt.
  • ADE20K – 0.68 mean IoU, demonstrating strong cross‑domain performance.
  • SA‑1B (held‑out) – 0.79 mean IoU, confirming that the model can recover masks that were never seen during training.
  • Prompt count vs. recall – With 5 random points per object, recall exceeds 95 % on most benchmark sets.

These numbers matter because they illustrate SAM’s ability to replace task‑specific segmenters with a single, general‑purpose model. Compared to earlier vision‑transformer segmenters (e.g., DeepLabV3+, Mask‑RCNN), the ViT‑Base SAM achieves comparable or superior IoU while requiring only a minimal prompt, making it faster for interactive workflows.


Hardware Requirements

VRAM for inference – The ViT‑Base encoder consumes roughly 4 GB of GPU memory for a 1024×1024 image when using FP16 (half‑precision). Adding the mask decoder and neck brings the total to about 5–6 GB. For batch‑size = 1, a 8 GB GPU (e.g., RTX 3060) is sufficient; larger batch sizes or higher‑resolution inputs benefit from 12 GB+ GPUs (RTX 3080, A5000, etc.).

Recommended GPU specifications

  • CUDA‑compatible GPU with at least 8 GB VRAM.
  • Support for Tensor Cores (for FP16 speed‑up).
  • Driver ≥ 525.0 and cuDNN ≥ 8.9.

CPU requirements – The model can be run on CPU‑only for prototyping, but inference speed drops dramatically (≈ 1 frame / second on a 12‑core Xeon). A modern multi‑core CPU (≥ 8 threads) is recommended for preprocessing and post‑processing.

Storage needs – The model checkpoint (safetensors) is ~1.2 GB. Including the tokenizer and image‑processor files adds ~200 MB. A total of ~1.5 GB of disk space is enough.

Performance characteristics – On an RTX 3080 (FP16), the end‑to‑end pipeline (image loading, prompt encoding, mask decoding) runs at ~30 fps for 1024×1024 images, making it suitable for real‑time interactive applications.


Use Cases

Primary applications

  • Interactive image editing tools – Users click on an object and instantly receive a precise mask.
  • Automated data annotation – A human annotator provides a few points per object, and SAM produces the full mask, dramatically reducing labeling time.
  • Robotics and autonomous systems – Prompt‑based segmentation enables a robot to focus on a specific item in cluttered scenes.
  • Medical image analysis – Radiologists can point to a lesion and obtain a refined segmentation for measurement or treatment planning.
  • AR/VR content creation – Real‑time mask generation allows virtual objects to be placed behind or in front of real‑world items.

Industry examples

  • e‑commerce – Automatic background removal for product photos using a single click.
  • Geospatial – Segmenting buildings or roads from satellite imagery with minimal human input.
  • Entertainment – Fast rotoscoping for video post‑production.
  • Healthcare – Segmentation of organs in MRI or CT scans for diagnostic assistance.

The model can be integrated via the transformers library (SamModel and SamProcessor) or exported to ONNX/TensorRT for deployment in edge devices.


Training Details

Methodology – SAM is trained in a two‑stage fashion. First, the ViT‑Base encoder is frozen while the Prompt Encoder and Mask Decoder learn to map prompts to masks. Afterwards, the entire network is fine‑tuned end‑to‑end on the massive SA‑1B dataset.

Dataset – The model leverages the SA‑1B dataset, comprising 11 million licensed images and 1.1 billion high‑quality masks. The dataset is privacy‑respecting and covers a broad spectrum of scenes (indoor, outdoor, synthetic, medical).

Compute requirements – Training the ViT‑Base SAM was performed on a cluster of 8‑GPU nodes (NVIDIA A100 40 GB) for roughly 12 days, using mixed‑precision (FP16) and AdamW optimizer. The total compute footprint is on the order of 3 kGPU‑hours.

Fine‑tuning capabilities – Because the model is prompt‑able, downstream tasks often need only a few hundred annotated examples to adapt. Users can fine‑tune the Mask Decoder on a target domain while keeping the Vision Encoder frozen, which reduces GPU memory and speeds up convergence.

The official repository provides scripts for both full‑scale pre‑training and lightweight fine‑tuning, making it straightforward to adapt SAM to niche applications such as satellite‑image segmentation or histopathology.


Licensing Information

The README explicitly lists the Apache‑2.0 license, which is a permissive open‑source licence. The “unknown” tag on the Hugging Face page reflects a metadata mismatch, not the actual legal terms.

  • Commercial use – Allowed without royalty. You may embed the model in paid products, SaaS offerings, or hardware devices.
  • Modification & redistribution – You may modify the source code or fine‑tune the weights, provided you retain the original copyright notice and include a copy of the Apache‑2.0 licence.
  • Patent grant – Apache‑2.0 includes an explicit patent‑use grant, protecting downstream users from patent claims by contributors.
  • Attribution – Required. Cite the original paper (see the “Related Papers” section) and retain the licence file in any distribution.

No additional restrictions (e.g., “non‑commercial” or “research‑only”) are imposed, making the model suitable for both academic research and production deployments.


Pre-loaded AI models. Ready to run.

Skip the downloads. Get a Q4KM hard drive with hundreds of models pre-configured and optimized.

Shop Q4KM Hard Drives