facebookresearch/sam3

GitHub: facebookresearch/sam3

Meta 推出的第三代「分割一切」基础模型,支持通过文本和视觉提示对图像与视频中的任意概念进行开放词汇的检测、分割和跟踪。

Stars: 11040 | Forks: 1667

# SAM 3:基于概念分割一切 Meta Superintelligence Labs [Nicolas Carion](https://www.nicolascarion.com/)\*, [Laura Gustafson](https://scholar.google.com/citations?user=c8IpF9gAAAAJ&hl=en)\*, [Yuan-Ting Hu](https://scholar.google.com/citations?user=E8DVVYQAAAAJ&hl=en)\*, [Shoubhik Debnath](https://scholar.google.com/citations?user=fb6FOfsAAAAJ&hl=en)\*, [Ronghang Hu](https://ronghanghu.com/)\*, [Didac Suris](https://www.didacsuris.com/)\*, [Chaitanya Ryali](https://scholar.google.com/citations?user=4LWx24UAAAAJ&hl=en)\*, [Kalyan Vasudev Alwala](https://scholar.google.co.in/citations?user=m34oaWEAAAAJ&hl=en)\*, [Haitham Khedr](https://hkhedr.com/)\*, Andrew Huang, [Jie Lei](https://jayleicn.github.io/), [Tengyu Ma](https://scholar.google.com/citations?user=VeTSl0wAAAAJ&hl=en), [Baishan Guo](https://scholar.google.com/citations?user=BC5wDu8AAAAJ&hl=en), Arpit Kalla, [Markus Marks](https://damaggu.github.io/), [Joseph Greer](https://scholar.google.com/citations?user=guL96CkAAAAJ&hl=en), Meng Wang, [Peize Sun](https://peizesun.github.io/), [Roman Rädle](https://scholar.google.com/citations?user=Tpt57v0AAAAJ&hl=en), [Triantafyllos Afouras](https://www.robots.ox.ac.uk/~afourast/), [Effrosyni Mavroudi](https://scholar.google.com/citations?user=vYRzGGEAAAAJ&hl=en), [Katherine Xu](https://k8xu.github.io/)°, [Tsung-Han Wu](https://patrickthwu.com/)°, [Yu Zhou](https://yu-bryan-zhou.github.io/)°, [Liliane Momeni](https://scholar.google.com/citations?user=Lb-KgVYAAAAJ&hl=en)°, [Rishi Hazra](https://rishihazra.github.io/)°, [Shuangrui Ding](https://mark12ding.github.io/)°, [Sagar Vaze](https://sgvaze.github.io/)°, [Francois Porcher](https://scholar.google.com/citations?user=LgHZ8hUAAAAJ&hl=en)°, [Feng Li](https://fengli-ust.github.io/)°, [Siyuan Li](https://siyuanliii.github.io/)°, [Aishwarya Kamath](https://ashkamath.github.io/)°, [Ho Kei Cheng](https://hkchengrex.com/)°, [Piotr Dollar](https://pdollar.github.io/)†, [Nikhila Ravi](https://nikhilaravi.com/)†, [Kate Saenko](https://ai.bu.edu/ksaenko.html)†, [Pengchuan Zhang](https://pzzhang.github.io/pzzhang/)†, [Christoph Feichtenhofer](https://feichtenhofer.github.io/)† \* 核心贡献者,° 实习生,† 项目负责人,各组内顺序随机 [[`论文`](https://ai.meta.com/research/publications/sam-3-segment-anything-with-concepts/)] [[`项目`](https://ai.meta.com/sam3)] [[`演示`](https://segment-anything.com/)] [[`博客`](https://ai.meta.com/blog/segment-anything-model-3/)] [[`BibTeX`](#citing-sam-3)] ![SAM 3 架构](https://static.pigsec.cn/wp-content/uploads/repos/cas/f1/f138d1aa02840a108b7b9578a817c974dc6fcb0e696c84121a48ff0976686ce9.png) SAM 3 是一个用于图像和视频中可提示分割的统一基础模型。它可以使用文本或视觉提示(例如点、框和掩码)来检测、分割和跟踪对象。与其前身 [SAM 2](https://github.com/facebookresearch/sam2) 相比,SAM 3 引入了穷举分割由短文本短语或样本指定的开放词汇概念的所有实例的能力。与之前的工作不同,SAM 3 可以处理大量更多的开放词汇提示。它在我们的全新 [SA-CO 基准](https://github.com/facebookresearch/sam3?tab=readme-ov-file#sa-co-dataset)上达到了 75-80% 的人类表现,该基准包含 27 万个独特概念,比现有基准多出 50 倍以上。 这一突破由一个创新的数据引擎驱动,该引擎已自动标注了超过 400 万个独特概念,创建了迄今为止最大的高质量开放词汇分割数据集。此外,SAM 3 引入了新的模型架构,其特点是包含一个存在 token,可改善对密切相关的文本提示的区分度(例如“穿白衣的球员”与“穿红衣的球员”),以及一种解耦的 detector–tracker 设计,可最大限度地减少任务干扰并随数据高效扩展。

## 最新更新 **03/27/2026 -- SAM 3.1 Object Multiplex 发布。它引入了一种用于联合多对象跟踪的共享内存方法,在不牺牲准确性的情况下显著提升了速度。** - 一套全新的改进版模型 checkpoint(表示为 **SAM 3.1**)已在 [Hugging Face](https://huggingface.co/facebook/sam3.1) 上发布。详情请参阅 [`RELEASE_SAM3p1.md`](RELEASE_SAM3p1.md)。 * 要使用新的 SAM 3.1 checkpoint,您需要此代码库中的最新模型代码。如果您安装了此代码库的早期版本,请从本代码库拉取最新代码(使用 `git pull`),然后按照下方的[安装说明](#installation)重新安装代码库。 ## 安装说明 ### 前置条件 - Python 3.12 或更高版本 - PyTorch 2.7 或更高版本 - 兼容 CUDA 的 GPU,且 CUDA 12.6 或更高版本 1. **创建一个新的 Conda 环境:** ``` conda create -n sam3 python=3.12 conda deactivate conda activate sam3 ``` 2. **安装支持 CUDA 的 PyTorch:** ``` pip install torch==2.10.0 torchvision --index-url https://download.pytorch.org/whl/cu128 ``` 3. **克隆代码库并安装包:** ``` git clone https://github.com/facebookresearch/sam3.git cd sam3 pip install -e . ``` 4. **安装用于示例 notebook 或开发的额外依赖项:** ``` # 运行示例 notebooks pip install -e ".[notebooks]" # 用于开发 pip install -e ".[train,dev]" ``` 5. **用于加速推理的可选依赖项** ``` pip install einops ninja && pip install flash-attn-3 --no-deps --index-url https://download.pytorch.org/whl/cu128 pip install git+https://github.com/ronghanghu/cc_torch.git ``` ## 快速入门 ⚠️ 在使用 SAM 3 之前,请申请访问 SAM 3 Hugging Face [代码库](https://huggingface.co/facebook/sam3) 中的 checkpoint。一旦获批,您 需要进行身份验证才能下载 checkpoint。您可以通过执行以下 [步骤](https://huggingface.co/docs/huggingface_hub/en/quick-start#authentication) 来实现(例如,生成访问 token 后运行 `hf auth login`。) ### 基本用法 ``` import torch #################################### For Image #################################### from PIL import Image from sam3.model_builder import build_sam3_image_model from sam3.model.sam3_image_processor import Sam3Processor # 加载模型 model = build_sam3_image_model() processor = Sam3Processor(model) # 加载图像 image = Image.open("") inference_state = processor.set_image(image) # 用文本提示模型 output = processor.set_text_prompt(state=inference_state, prompt="") # 获取 masks、bounding boxes 和 scores masks, boxes, scores = output["masks"], output["boxes"], output["scores"] #################################### For Video #################################### from sam3.model_builder import build_sam3_video_predictor video_predictor = build_sam3_video_predictor() video_path = "" # a JPEG folder or an MP4 video file # 启动 session response = video_predictor.handle_request( request=dict( type="start_session", resource_path=video_path, ) ) response = video_predictor.handle_request( request=dict( type="add_prompt", session_id=response["session_id"], frame_index=0, # Arbitrary frame index text="", ) ) output = response["outputs"] ``` ## 示例 `examples` 目录包含了一些 notebook,展示了如何使用各种类型的提示来运行 SAM3: - [`sam3_image_predictor_example.ipynb`](examples/sam3_image_predictor_example.ipynb) : 演示如何在图像上使用文本和视觉框提示 SAM 3。 - [`sam3_video_predictor_example.ipynb`](examples/sam3_video_predictor_example.ipynb) : 演示如何在视频上使用文本提示 SAM 3,并使用点进行进一步的交互式修正。 - [`sam3_image_batched_inference.ipynb`](examples/sam3_image_batched_inference.ipynb) : 演示如何在图像上使用 SAM 3 运行批量推理。 - [`sam3_agent.ipynb`](examples/sam3_agent.ipynb): 演示如何使用 SAM 3 Agent 对图像上的复杂文本提示进行分割。 - [`saco_gold_silver_vis_example.ipynb`](examples/saco_gold_silver_vis_example.ipynb) : 展示了 SA-Co 图像评估集中的一些示例。 - [`saco_veval_vis_example.ipynb`](examples/saco_veval_vis_example.ipynb) : 展示了 SA-Co 视频评估集中的一些示例。 examples 目录中还有其他 notebook,演示了如何在图像和视频中 使用 SAM 3 进行交互式实例分割(SAM 1/2 任务),或将其作为 MLLM 的工具,以及如何在 SA-Co 数据集上运行评估。 要运行 Jupyter notebook 示例: ``` # 确保已安装 notebooks 依赖 pip install -e ".[notebooks]" # 启动 Jupyter notebook jupyter notebook examples/sam3_image_predictor_example.ipynb ``` ## 模型 SAM 3 由一个 detector 和一个共享 vision encoder 的 tracker 组成。它拥有 8.48 亿个参数。 detector 是一个基于 DETR 的模型,以文本、几何和图像 样本为条件。tracker 继承了 SAM 2 的 transformer encoder-decoder 架构,支持视频分割和交互式修正。 ## 图像结果
模型 实例分割 框检测
LVIS SA-Co/Gold LVIS COCO SA-Co/Gold
cgF1 AP cgF1 cgF1 AP AP APo cgF1
人类 - - 72.8 - - - - 74.0
OWLv2* 29.3 43.4 24.6 30.2 45.5 46.1 23.9 24.5
DINO-X - 38.5 21.3 - 52. 56.0 - 22.5
Gemini 2.5 13.4 - 13.0 16.1 - - - 14.4
SAM 3 37.2 48.5 54.1 40.6 53.6 56.4 55.7 55.7

* 在 LVIS 上进行了部分训练,APo 指的是 COCO-O 准确率

## 视频结果
模型 SA-V 测试集 YT-Temporal-1B 测试集 SmartGlasses 测试集 LVVIS 测试集 BURST 测试集
cgF1 pHOTA cgF1 pHOTA cgF1 pHOTA mAP HOTA
人类 53.1 70.5 71.2 78.4 58.5 72.3 - -
SAM 3 30.3 58.0 50.8 69.9 36.4 63.6 36.3 44.5
## SA-Co 数据集 我们发布了 2 个图像基准,[SA-Co/Gold](scripts/eval/gold/README.md) 和 [SA-Co/Silver](scripts/eval/silver/README.md),以及一个视频基准 [SA-Co/VEval](scripts/eval/veval/README.md)。这些数据集包含带有标注名词短语的图像(或视频)。每一对图像/视频和名词短语都标注了实例掩码以及每个与短语匹配的对象的唯一 ID。没有匹配对象的短语(负提示)没有掩码,在图中以红色字体显示。请参阅链接的 README 以获取有关如何下载数据集并在其上运行评估的更多详细信息。 * HuggingFace 托管:[SA-Co/Gold](https://huggingface.co/datasets/facebook/SACo-Gold)、[SA-Co/Silver](https://huggingface.co/datasets/facebook/SACo-Silver) 和 [SA-Co/VEval](https://huggingface.co/datasets/facebook/SACo-VEval) * Roboflow 托管:[SA-Co/Gold](https://universe.roboflow.com/sa-co-gold)、[SA-Co/Silver](https://universe.roboflow.com/sa-co-silver) 和 [SA-Co/VEval](https://universe.roboflow.com/sa-co-veval) ![SA-Co 数据集](https://static.pigsec.cn/wp-content/uploads/repos/cas/f1/f1ddd6e5d4130cb37e0b41f474ac78e75483db1b8964552b042bc8bef03b9cd1.jpg) ## 开发 要设置开发环境: ``` pip install -e ".[dev,train]" ``` 格式化代码: ``` ufmt format . ``` ## 许可证 本项目根据 SAM 许可证授权 - 详情请参阅 [LICENSE](LICENSE) 文件。 ## 致谢 我们要感谢以下人员对 SAM 3 项目做出的贡献:Alex He、Alexander Kirillov、 Alyssa Newcomb、Ana Paula Kirschner Mofarrej、Andrea Madotto、Andrew Westbury、Ashley Gabriel、Azita Shokpour、 Ben Samples、Bernie Huang、Carleigh Wood、Ching-Feng Yeh、Christian Puhrsch、Claudette Ward、Daniel Bolya、 Daniel Li、Facundo Figueroa、Fazila Vhora、George Orlin、Hanzi Mao、Helen Klein、Hu Xu、Ida Cheng、Jake Kinney、 Jiale Zhi、Jo Sampaio、Joel Schlosser、Justin Johnson、Kai Brown、Karen Bergan、Karla Martucci、Kenny Lehmann、 Maddie Mintz、Mallika Malhotra、Matt Ward、Michelle Chan、Michelle Restrepo、Miranda Hartley、Muhammad Maaz、 Nisha Deo、Peter Park、Phillip Thomas、Raghu Nayani、Rene Martinez Doehner、Robbie Adkins、Ross Girshik、Sasha Mitts、Shashank Jain、Spencer Whitehead、Ty Toledano、Valentin Gabeur、Vincent Cho、Vivian Lee、William Ngan、 Xuehai He、Yael Yungster、Ziqi Pang、Ziyi Dou、Zoe Quake。 ## 引用 SAM 3 如果您在研究中使用了 SAM 3 或 SA-Co 数据集,请使用以下 BibTeX 条目。 ``` @misc{carion2025sam3segmentconcepts, title={SAM 3: Segment Anything with Concepts}, author={Nicolas Carion and Laura Gustafson and Yuan-Ting Hu and Shoubhik Debnath and Ronghang Hu and Didac Suris and Chaitanya Ryali and Kalyan Vasudev Alwala and Haitham Khedr and Andrew Huang and Jie Lei and Tengyu Ma and Baishan Guo and Arpit Kalla and Markus Marks and Joseph Greer and Meng Wang and Peize Sun and Roman Rädle and Triantafyllos Afouras and Effrosyni Mavroudi and Katherine Xu and Tsung-Han Wu and Yu Zhou and Liliane Momeni and Rishi Hazra and Shuangrui Ding and Sagar Vaze and Francois Porcher and Feng Li and Siyuan Li and Aishwarya Kamath and Ho Kei Cheng and Piotr Dollár and Nikhila Ravi and Kate Saenko and Pengchuan Zhang and Christoph Feichtenhofer}, year={2025}, eprint={2511.16719}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2511.16719}, } ```
标签:NoSQL, SAM 3, Vectored Exception Handling, 人工智能, 凭据扫描, 图像分割, 推理, 模型微调, 用户模式Hook绕过, 计算机视觉, 逆向工具