docs: rewrite model card with variants table, citation, AnyLabeling cross-link
Browse files
README.md
CHANGED
|
@@ -1,151 +1,84 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
-
-
|
| 5 |
-
-
|
| 6 |
-
- segment-anything
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
# Segment Anything 3 (SAM 3) — ONNX Models
|
| 17 |
|
| 18 |
-
ONNX
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
##
|
| 25 |
|
| 26 |
-
| File |
|
| 27 |
-
|---
|
| 28 |
-
| `sam3_vit_h.zip` |
|
| 29 |
|
| 30 |
-
The zip
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|-----------|------|------|
|
| 34 |
-
| `sam3_image_encoder.onnx` | Extracts visual features from the input image | Once per image |
|
| 35 |
-
| `sam3_language_encoder.onnx` | Encodes text prompt tokens into feature vectors | Once per text query |
|
| 36 |
-
| `sam3_decoder.onnx` | Produces segmentation masks given image + language features | Per prompt |
|
| 37 |
-
|
| 38 |
-
## Prompt Types
|
| 39 |
-
|
| 40 |
-
SAM 3 supports **three prompt modalities**:
|
| 41 |
-
|
| 42 |
-
| Prompt | Description |
|
| 43 |
-
|--------|-------------|
|
| 44 |
-
| **Text** | Natural-language description, e.g. `"truck"` — unique to SAM 3 |
|
| 45 |
-
| **Point** | Click `+point` / `-point` to include/exclude regions |
|
| 46 |
-
| **Rectangle** | Draw a bounding box around the target object |
|
| 47 |
-
|
| 48 |
-
Text prompts are the recommended workflow: they drive detection open-vocabulary style, so you can label **any object class** without retraining.
|
| 49 |
-
|
| 50 |
-
## Use with AnyLabeling (Recommended)
|
| 51 |
-
|
| 52 |
-
[AnyLabeling](https://github.com/vietanhdev/anylabeling) is a desktop annotation tool with a built-in model manager that downloads, caches, and runs these models automatically — no coding required.
|
| 53 |
-
|
| 54 |
-
1. Install: `pip install anylabeling`
|
| 55 |
-
2. Launch: `anylabeling`
|
| 56 |
-
3. Click the **Brain** button → select **Segment Anything 3 (ViT-H)** from the dropdown
|
| 57 |
-
4. Type a text description (e.g., `truck`) in the text prompt field
|
| 58 |
-
5. Optionally refine with point/rectangle prompts
|
| 59 |
-
|
| 60 |
-
[](https://github.com/vietanhdev/anylabeling)
|
| 61 |
-
|
| 62 |
-
## Use Programmatically with ONNX Runtime
|
| 63 |
-
|
| 64 |
-
```python
|
| 65 |
-
import urllib.request, zipfile
|
| 66 |
-
url = "https://huggingface.co/vietanhdev/segment-anything-3-onnx-models/resolve/main/sam3_vit_h.zip"
|
| 67 |
-
urllib.request.urlretrieve(url, "sam3_vit_h.zip")
|
| 68 |
-
with zipfile.ZipFile("sam3_vit_h.zip") as z:
|
| 69 |
-
z.extractall("sam3")
|
| 70 |
-
```
|
| 71 |
-
|
| 72 |
-
Then use [samexporter](https://github.com/vietanhdev/samexporter)'s inference module:
|
| 73 |
|
| 74 |
```bash
|
| 75 |
-
pip install
|
| 76 |
-
|
| 77 |
-
# Text prompt
|
| 78 |
-
python -m samexporter.inference \
|
| 79 |
-
--sam_variant sam3 \
|
| 80 |
-
--encoder_model sam3/sam3_image_encoder.onnx \
|
| 81 |
-
--decoder_model sam3/sam3_decoder.onnx \
|
| 82 |
-
--language_encoder_model sam3/sam3_language_encoder.onnx \
|
| 83 |
-
--image photo.jpg \
|
| 84 |
-
--prompt prompt.json \
|
| 85 |
-
--text_prompt "truck" \
|
| 86 |
-
--output result.png
|
| 87 |
-
```
|
| 88 |
-
|
| 89 |
-
Example `prompt.json` for a text-only query:
|
| 90 |
-
```json
|
| 91 |
-
[{"type": "text", "data": "truck"}]
|
| 92 |
```
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
```
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
## Re-export from Source
|
| 109 |
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
-
pip install samexporter
|
| 114 |
|
| 115 |
-
#
|
| 116 |
-
python -m samexporter.export_sam3 --output_dir output_models/sam3
|
| 117 |
|
| 118 |
-
|
| 119 |
-
bash convert_sam3.sh
|
| 120 |
-
```
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
-
```
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
input_size: 1008
|
| 134 |
-
max_height: 1008
|
| 135 |
-
max_width: 1008
|
| 136 |
```
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
## Related Repositories
|
| 141 |
-
|
| 142 |
-
| Repo | Description |
|
| 143 |
-
|------|-------------|
|
| 144 |
-
| [vietanhdev/samexporter](https://github.com/vietanhdev/samexporter) | Export scripts, inference code, conversion tools |
|
| 145 |
-
| [vietanhdev/anylabeling](https://github.com/vietanhdev/anylabeling) | Desktop annotation app powered by these models |
|
| 146 |
-
| [facebook/sam3](https://huggingface.co/facebook/sam3) | Original SAM 3 PyTorch checkpoint by Meta |
|
| 147 |
|
| 148 |
-
##
|
| 149 |
|
| 150 |
-
|
| 151 |
-
The export code is part of [samexporter](https://github.com/vietanhdev/samexporter), released under the **MIT** license.
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
library_name: onnx
|
| 5 |
+
base_model: facebook/sam3
|
| 6 |
tags:
|
| 7 |
+
- onnxruntime
|
| 8 |
+
- onnx
|
| 9 |
+
- segment-anything
|
| 10 |
+
- segment-anything-3
|
| 11 |
+
- image-segmentation
|
| 12 |
+
- open-vocabulary
|
| 13 |
+
- text-to-segmentation
|
| 14 |
+
- edge-ai
|
| 15 |
+
- anylabeling
|
| 16 |
+
authors:
|
| 17 |
+
- Viet-Anh Nguyen
|
| 18 |
---
|
| 19 |
|
| 20 |
# Segment Anything 3 (SAM 3) — ONNX Models
|
| 21 |
|
| 22 |
+
ONNX export of Meta's [SAM 3](https://huggingface.co/facebook/sam3) — the open-vocabulary, text-promptable segmentation model — packaged for use with [`onnxruntime`](https://onnxruntime.ai) and [AnyLabeling](https://github.com/vietanhdev/anylabeling).
|
| 23 |
|
| 24 |
+
## Why this repo exists
|
| 25 |
|
| 26 |
+
SAM 3 brings open-vocabulary text prompts to the SAM family: instead of clicking points or drawing boxes, you can describe the object in natural language and the model segments it. ONNX gives you a portable, dependency-light runtime that works in Python, C++, JavaScript, and most embedded targets. This is the export that AnyLabeling consumes for its smart-labeling features.
|
| 27 |
|
| 28 |
+
## Variants
|
| 29 |
|
| 30 |
+
| File | Backbone | Size |
|
| 31 |
+
|---|---|---|
|
| 32 |
+
| `sam3_vit_h.zip` | ViT-H | 3.2 GB |
|
| 33 |
|
| 34 |
+
The zip bundles the encoder + decoder + text-prompt encoder ONNX files for the ViT-H backbone.
|
| 35 |
|
| 36 |
+
## Quick start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
```bash
|
| 39 |
+
pip install huggingface_hub onnxruntime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
```
|
| 41 |
|
| 42 |
+
```python
|
| 43 |
+
from huggingface_hub import hf_hub_download
|
| 44 |
+
import zipfile, onnxruntime as ort
|
| 45 |
+
|
| 46 |
+
zip_path = hf_hub_download(repo_id="vietanhdev/segment-anything-3-onnx-models",
|
| 47 |
+
filename="sam3_vit_h.zip")
|
| 48 |
+
with zipfile.ZipFile(zip_path) as z:
|
| 49 |
+
z.extractall("./sam3")
|
| 50 |
+
|
| 51 |
+
# Inspect the unzipped files and load the components you need:
|
| 52 |
+
import os
|
| 53 |
+
for f in sorted(os.listdir("./sam3")):
|
| 54 |
+
print(f)
|
| 55 |
```
|
| 56 |
|
| 57 |
+
For the full text → mask pipeline, see how AnyLabeling wires it: <https://github.com/vietanhdev/anylabeling>
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
## Use with AnyLabeling
|
| 60 |
|
| 61 |
+
These models drop into AnyLabeling's auto-labeling backend without conversion. See the [AnyLabeling docs](https://github.com/vietanhdev/anylabeling) for the model-config wiring.
|
|
|
|
| 62 |
|
| 63 |
+
## Source weights
|
|
|
|
| 64 |
|
| 65 |
+
Original SAM 3 weights and license: <https://huggingface.co/facebook/sam3>
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
This repo redistributes the same weights in ONNX format. License unchanged from upstream (Apache 2.0).
|
| 68 |
|
| 69 |
+
## Citation
|
| 70 |
|
| 71 |
+
```bibtex
|
| 72 |
+
@misc{nguyen2026sam3_onnx,
|
| 73 |
+
author = {Nguyen, Viet-Anh and {Neural Research Lab}},
|
| 74 |
+
title = {SAM 3 ONNX Models},
|
| 75 |
+
year = {2026},
|
| 76 |
+
url = {https://huggingface.co/vietanhdev/segment-anything-3-onnx-models}
|
| 77 |
+
}
|
|
|
|
|
|
|
|
|
|
| 78 |
```
|
| 79 |
|
| 80 |
+
For the underlying model, cite Meta's SAM 3 release (see <https://huggingface.co/facebook/sam3> for the canonical citation).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
## Acknowledgments
|
| 83 |
|
| 84 |
+
Thanks to Meta AI Research for releasing SAM 3 with open weights. This repo packages their work for edge inference.
|
|
|