siliconflow/sam2
forked from facebookresearch/sam2
Captured source
source ↗siliconflow/sam2
Description: The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Language: Jupyter Notebook
License: Apache-2.0
Stars: 0
Forks: 0
Open issues: 0
Created: 2025-08-08T08:11:59Z
Pushed: 2025-08-08T08:19:36Z
Default branch: main
Fork: yes
Parent repository: facebookresearch/sam2
Archived: no
README:
SAM 2: Segment Anything in Images and Videos
[AI at Meta, FAIR](https://ai.meta.com/research/)
Nikhila Ravi, Valentin Gabeur, Yuan-Ting Hu, Ronghang Hu, Chaitanya Ryali, Tengyu Ma, Haitham Khedr, Roman Rädle, Chloe Rolland, Laura Gustafson, Eric Mintun, Junting Pan, Kalyan Vasudev Alwala, Nicolas Carion, Chao-Yuan Wu, Ross Girshick, Piotr Dollár, Christoph Feichtenhofer
[`Paper`] [`Project`] [`Demo`] [`Dataset`] [`Blog`] [[BibTeX](#citing-sam-2)]

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.

Latest updates
12/11/2024 -- full model compilation for a major VOS speedup and a new `SAM2VideoPredictor` to better handle multi-object tracking
- We now support
torch.compileof the entire SAM 2 model on videos, which can be turned on by settingvos_optimized=Trueinbuild_sam2_video_predictor, leading to a major speedup for VOS inference. - We update the implementation of
SAM2VideoPredictorto support independent per-object inference, allowing us to relax the assumption of prompting for multi-object tracking and adding new objects after tracking starts. - See [
RELEASE_NOTES.md](RELEASE_NOTES.md) for full details.
09/30/2024 -- SAM 2.1 Developer Suite (new checkpoints, training code, web demo) is released
- A new suite of improved model checkpoints (denoted as SAM 2.1) are released. See [Model Description](#model-description) for details.
- To use the new SAM 2.1 checkpoints, you need the latest model code from this repo. If you have installed an earlier version of this repo, please first uninstall the previous version via
pip uninstall SAM-2, pull the latest code from this repo (withgit pull), and then reinstall the repo following [Installation](#installation) below. - The training (and fine-tuning) code has been released. See [
training/README.md](training/README.md) on how to get started. - The frontend + backend code for the SAM 2 web demo has been released. See [
demo/README.md](demo/README.md) for details.
Installation
SAM 2 needs to be installed first before use. The code requires python>=3.10, as well as torch>=2.5.1 and torchvision>=0.20.1. Please follow the instructions here to install both PyTorch and TorchVision dependencies. You can install SAM 2 on a GPU machine using:
git clone https://github.com/facebookresearch/sam2.git && cd sam2 pip install -e .
If you are installing on Windows, it's strongly recommended to use Windows Subsystem for Linux (WSL) with Ubuntu.
To use the SAM 2 predictor and run the example notebooks, jupyter and matplotlib are required and can be installed by:
pip install -e ".[notebooks]"
Note: 1. It's recommended to create a new Python environment via Anaconda for this installation and install PyTorch 2.5.1 (or higher) via pip following https://pytorch.org/. If you have a PyTorch version lower than 2.5.1 in your current environment, the installation command above will try to upgrade it to the latest PyTorch version using pip. 2. The step above requires compiling a custom CUDA kernel with the nvcc compiler. If it isn't already available on your machine, please install the CUDA toolkits with a version that matches your PyTorch CUDA version. 3. If you see a message like Failed to build the SAM 2 CUDA extension during installation, you can ignore it and still use SAM 2 (some post-processing functionality may be limited, but it doesn't affect the results in most cases).
Please see [INSTALL.md](./INSTALL.md) for FAQs on potential issues and solutions.
Getting Started
Download Checkpoints
First, we need to download a model checkpoint. All the model checkpoints can be downloaded by running:
cd checkpoints && \ ./download_ckpts.sh && \ cd ..
or individually from:
-…
Excerpt shown — open the source for the full document.
Notability
notability 2.0/10Routine fork of SAM2 repo.