facebook / sam-vit-base

huggingface.co
Total runs: 692.7K
24-hour runs: 0
7-day runs: 86.7K
30-day runs: -808.4K
Model's Last Updated: January 12 2024
mask-generation

Introduction of sam-vit-base

Model Details of sam-vit-base

Model Card for Segment Anything Model (SAM) - ViT Base (ViT-B) version

Model architecture Detailed architecture of Segment Anything Model (SAM).

Table of Contents

  1. TL;DR
  2. Model Details
  3. Usage
  4. Citation

TL;DR

Link to original repository

Snow Forest Mountains

The Segment Anything Model (SAM) produces high quality object masks from input prompts such as points or boxes, and it can be used to generate masks for all objects in an image. It has been trained on a dataset of 11 million images and 1.1 billion masks, and has strong zero-shot performance on a variety of segmentation tasks. The abstract of the paper states:

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.

Disclaimer : Content from this model card has been written by the Hugging Face team, and parts of it were copy pasted from the original SAM model card .

Model Details

The SAM model is made up of 3 modules:

  • The VisionEncoder : a VIT based image encoder. It computes the image embeddings using attention on patches of the image. Relative Positional Embedding is used.
  • The PromptEncoder : generates embeddings for points and bounding boxes
  • The MaskDecoder : a two-ways transformer which performs cross attention between the image embedding and the point embeddings (->) and between the point embeddings and the image embeddings. The outputs are fed
  • The Neck : predicts the output masks based on the contextualized masks produced by the MaskDecoder .

Usage

Prompted-Mask-Generation
from PIL import Image
import requests
from transformers import SamModel, SamProcessor

model = SamModel.from_pretrained("facebook/sam-vit-base")
processor = SamProcessor.from_pretrained("facebook/sam-vit-base")

img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
input_points = [[[450, 600]]] # 2D localization of a window
inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to("cuda")
outputs = model(**inputs)
masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
scores = outputs.iou_scores

Among other arguments to generate masks, you can pass 2D locations on the approximate position of your object of interest, a bounding box wrapping the object of interest (the format should be x, y coordinate of the top right and bottom left point of the bounding box), a segmentation mask. At this time of writing, passing a text as input is not supported by the official model according to the official repository . For more details, refer to this notebook, which shows a walk throught of how to use the model, with a visual example!

Automatic-Mask-Generation

The model can be used for generating segmentation masks in a "zero-shot" fashion, given an input image. The model is automatically prompt with a grid of 1024 points which are all fed to the model.

The pipeline is made for automatic mask generation. The following snippet demonstrates how easy you can run it (on any device! Simply feed the appropriate points_per_batch argument)

from transformers import pipeline
generator =  pipeline("mask-generation", device = 0, points_per_batch = 256)
image_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
outputs = generator(image_url, points_per_batch = 256)

Now to display the image:

import matplotlib.pyplot as plt
from PIL import Image
import numpy as np

def show_mask(mask, ax, random_color=False):
    if random_color:
        color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
    else:
        color = np.array([30 / 255, 144 / 255, 255 / 255, 0.6])
    h, w = mask.shape[-2:]
    mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
    ax.imshow(mask_image)
    

plt.imshow(np.array(raw_image))
ax = plt.gca()
for mask in outputs["masks"]:
    show_mask(mask, ax=ax, random_color=True)
plt.axis("off")
plt.show()

Citation

If you use this model, please use the following BibTeX entry.

@article{kirillov2023segany,
  title={Segment Anything},
  author={Kirillov, Alexander and Mintun, Eric and Ravi, Nikhila and Mao, Hanzi and Rolland, Chloe and Gustafson, Laura and Xiao, Tete and Whitehead, Spencer and Berg, Alexander C. and Lo, Wan-Yen and Doll{\'a}r, Piotr and Girshick, Ross},
  journal={arXiv:2304.02643},
  year={2023}
}

Runs of facebook sam-vit-base on huggingface.co

692.7K
Total runs
0
24-hour runs
9.4K
3-day runs
86.7K
7-day runs
-808.4K
30-day runs

More Information About sam-vit-base huggingface.co Model

More sam-vit-base license Visit here:

https://choosealicense.com/licenses/apache-2.0

sam-vit-base huggingface.co

sam-vit-base huggingface.co is an AI model on huggingface.co that provides sam-vit-base's model effect (), which can be used instantly with this facebook sam-vit-base model. huggingface.co supports a free trial of the sam-vit-base model, and also provides paid use of the sam-vit-base. Support call sam-vit-base model through api, including Node.js, Python, http.

sam-vit-base huggingface.co Url

https://huggingface.co/facebook/sam-vit-base

facebook sam-vit-base online free

sam-vit-base huggingface.co is an online trial and call api platform, which integrates sam-vit-base's modeling effects, including api services, and provides a free online trial of sam-vit-base, you can try sam-vit-base online for free by clicking the link below.

facebook sam-vit-base online free url in huggingface.co:

https://huggingface.co/facebook/sam-vit-base

sam-vit-base install

sam-vit-base is an open source model from GitHub that offers a free installation service, and any user can find sam-vit-base on GitHub to install. At the same time, huggingface.co provides the effect of sam-vit-base install, users can directly use sam-vit-base installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

sam-vit-base install url in huggingface.co:

https://huggingface.co/facebook/sam-vit-base

Url of sam-vit-base

sam-vit-base huggingface.co Url

Provider of sam-vit-base huggingface.co

facebook
ORGANIZATIONS

Other API from facebook

huggingface.co

Total runs: 14.8M
Run Growth: -1.8M
Growth Rate: -11.66%
Updated:September 15 2023
huggingface.co

Total runs: 8.0M
Run Growth: 440.4K
Growth Rate: 5.47%
Updated:January 20 2022
huggingface.co

Total runs: 4.8M
Run Growth: 1.6M
Growth Rate: 32.95%
Updated:September 06 2023
huggingface.co

Total runs: 3.3M
Run Growth: -573.9K
Growth Rate: -17.53%
Updated:December 28 2021
huggingface.co

Total runs: 2.6M
Run Growth: 433.5K
Growth Rate: 16.57%
Updated:January 17 2024
huggingface.co

Total runs: 2.2M
Run Growth: 23.6K
Growth Rate: 1.07%
Updated:November 21 2025
huggingface.co

Total runs: 2.1M
Run Growth: 566.1K
Growth Rate: 27.51%
Updated:March 23 2023
huggingface.co

Total runs: 1.8M
Run Growth: -356.7K
Growth Rate: -20.06%
Updated:January 25 2024
huggingface.co

Total runs: 821.3K
Run Growth: -255.5K
Growth Rate: -30.67%
Updated:September 06 2023
huggingface.co

Total runs: 588.3K
Run Growth: 120.7K
Growth Rate: 20.18%
Updated:May 22 2023
huggingface.co

Total runs: 499.7K
Run Growth: 155.4K
Growth Rate: 31.09%
Updated:March 17 2025
huggingface.co

Total runs: 387.0K
Run Growth: 40.6K
Growth Rate: 10.59%
Updated:February 29 2024
huggingface.co

Total runs: 381.0K
Run Growth: -86.9K
Growth Rate: -22.25%
Updated:January 12 2024
huggingface.co

Total runs: 370.6K
Run Growth: 222.1K
Growth Rate: 59.54%
Updated:September 06 2023
huggingface.co

Total runs: 341.1K
Run Growth: -470.4K
Growth Rate: -137.59%
Updated:July 25 2023
huggingface.co

Total runs: 323.4K
Run Growth: -80.3K
Growth Rate: -24.85%
Updated:November 17 2022
huggingface.co

Total runs: 237.3K
Run Growth: -44.5K
Growth Rate: -18.81%
Updated:June 15 2023
huggingface.co

Total runs: 236.9K
Run Growth: 14.3K
Growth Rate: 6.02%
Updated:July 23 2024
huggingface.co

Total runs: 231.8K
Run Growth: -14.2K
Growth Rate: -6.04%
Updated:September 15 2023
huggingface.co

Total runs: 229.5K
Run Growth: 28.0K
Growth Rate: 12.18%
Updated:June 13 2023
huggingface.co

Total runs: 199.4K
Run Growth: 65.8K
Growth Rate: 33.00%
Updated:May 22 2023
huggingface.co

Total runs: 162.8K
Run Growth: 1.6K
Growth Rate: 0.97%
Updated:September 01 2023
huggingface.co

Total runs: 153.5K
Run Growth: 43.1K
Growth Rate: 28.99%
Updated:February 12 2023
huggingface.co

Total runs: 137.2K
Run Growth: 39.6K
Growth Rate: 28.54%
Updated:June 13 2023
huggingface.co

Total runs: 134.2K
Run Growth: -121.7K
Growth Rate: -89.31%
Updated:June 13 2023
huggingface.co

Total runs: 131.7K
Run Growth: -17.0K
Growth Rate: -13.12%
Updated:June 03 2022
huggingface.co

Total runs: 117.1K
Run Growth: -28.8K
Growth Rate: -25.12%
Updated:September 15 2023
huggingface.co

Total runs: 112.8K
Run Growth: 6.6K
Growth Rate: 6.03%
Updated:September 06 2023
huggingface.co

Total runs: 98.2K
Run Growth: 88.6K
Growth Rate: 90.46%
Updated:September 06 2023
huggingface.co

Total runs: 86.0K
Run Growth: 578
Growth Rate: 0.67%
Updated:January 25 2023
huggingface.co

Total runs: 84.9K
Run Growth: -14.4K
Growth Rate: -16.91%
Updated:November 20 2023
huggingface.co

Total runs: 81.1K
Run Growth: -8.5K
Growth Rate: -11.21%
Updated:November 16 2023
huggingface.co

Total runs: 79.2K
Run Growth: -2.1K
Growth Rate: -2.67%
Updated:March 28 2026
huggingface.co

Total runs: 76.0K
Run Growth: 39.6K
Growth Rate: 51.22%
Updated:June 13 2023
huggingface.co

Total runs: 69.9K
Run Growth: 51.9K
Growth Rate: 74.21%
Updated:January 29 2026
huggingface.co

Total runs: 68.5K
Run Growth: 59.5K
Growth Rate: 86.41%
Updated:September 01 2023
huggingface.co

Total runs: 63.8K
Run Growth: 19.4K
Growth Rate: 30.48%
Updated:March 27 2026
huggingface.co

Total runs: 51.8K
Run Growth: 23.9K
Growth Rate: 46.34%
Updated:March 13 2024