facebookresearch / segment-anything
git clone https://github.com/facebookresearch/segment-anything.git
🔥 on GitHub Trending today
The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
—
stars, 24h
+69
stars, 7 days · #721
—
stars, 30 days
55k
★ total · +0% this week
6.4k
forks · 536 open issues
Star history starts 2026-10-20; the chart appears after the second daily snapshot.
LanguageJupyter Notebook
LicenseApache-2.0
Created2023-03-23 (3y ago)
Last push2y ago
Watchers338
OwnerOrganization
Seen on GitHub Trending
- 2026-10-20 — #17 weekly in jupyter-notebook · +69 ★
Links
README excerpt
## Latest updates -- SAM 2: Segment Anything in Images and Videos Please check out our new release on **Segment Anything Model 2 (SAM 2)**. * SAM 2 code: https://github.com/facebookresearch/segment-anything-2 * SAM 2 demo: https://sam2.metademolab.com/ * SAM 2 paper: https://arxiv.org/abs/2408.00714 **Segment Anything Model 2 (SAM 2)** is a foundation model towards solving promptable visual segmentation in images and videos. We extend SAM to video by considering images as a video with a single frame. The model design is a simple transformer architecture with streaming memory for real-time video processing. We build a model-in-the-loop data engine, which improves model and data via user interaction, to collect **our SA-V dataset**, the largest video segmentation dataset to date. SAM 2 trained on our data provides strong performance across a wide range of tasks and visual domains. # Segment Anything **Meta AI Research, FAIR** Alexander Kirillov, Eric Mintun, Nikhila Ravi, Hanzi Mao, Chloe Rolland, Laura Gustafson, Tete Xiao, Spencer Whitehead, Alex Berg, Wan-Yen Lo, Piotr Dollar, Ross Girshick [`Paper`] [`Project`] [`Demo`] [`Dataset`] [`Blog`] [`BibTeX`] 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. ## Installation The code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. Please follow the instructions here to install both PyTorch and TorchVision dependencies. Installing both PyTorch and TorchVision with CUDA support is strongly recommended. Install Segment Anything: [code] or clone the repository locally and install with [code] The following optional dependencies are necessary for mask post-processing, saving masks in COCO format, the example notebooks, and exporting the model in ONNX format. `jupyter` is also required to run the example notebooks. [code] ## Getting Started First download a model checkpoint. Then the model can be used in just a few lines to get masks from a given prompt: [code] or generate masks for an entire image: [code] Additionally, masks can be generated for images from the command line: [code] See the examples notebooks on using SAM with prompts and automatically generating masks for more details. ## ONNX Export SAM's lightweight mask decoder can be exported to ONNX format so that it can be run in any environment that supports ONNX runtime, such as in-browser as showcased in the demo. Export the model with [code] See the example notebook for details on how to combine image preprocessing via SAM's backbone with mask prediction using the ONNX model. It is recommended to use the latest stable version of PyTorch for ONNX export. ### Web demo The `demo/` folder has a simple one page React app which shows how t