docs: rewrite model card with variants table, citation, AnyLabeling cross-link
Browse files
README.md
CHANGED
|
@@ -1,101 +1,97 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
|
| 9 |
-
--
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
## License
|
| 99 |
-
|
| 100 |
-
The ONNX models are derived from Meta's SAM and MobileSAM, both released under the **Apache 2.0** license.
|
| 101 |
-
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 |
+
tags:
|
| 6 |
+
- onnxruntime
|
| 7 |
+
- onnx
|
| 8 |
+
- segment-anything
|
| 9 |
+
- image-segmentation
|
| 10 |
+
- edge-ai
|
| 11 |
+
- anylabeling
|
| 12 |
+
authors:
|
| 13 |
+
- Viet-Anh Nguyen
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# Segment Anything (SAM) — ONNX Models
|
| 17 |
+
|
| 18 |
+
ONNX exports of Meta's original [Segment Anything](https://github.com/facebookresearch/segment-anything) family, plus [MobileSAM](https://github.com/ChaoningZhang/MobileSAM), packaged for direct use with [`onnxruntime`](https://onnxruntime.ai) and [AnyLabeling](https://github.com/vietanhdev/anylabeling).
|
| 19 |
+
|
| 20 |
+
## Why this repo exists
|
| 21 |
+
|
| 22 |
+
Running SAM through the original PyTorch checkpoint is heavy on a CPU laptop or an edge device. ONNX gives you a portable, dependency-light runtime that works in Python, C++, JavaScript, and most embedded targets. These exports are the ones AnyLabeling consumes for its smart-labeling features.
|
| 23 |
+
|
| 24 |
+
## Variants
|
| 25 |
+
|
| 26 |
+
Each `.zip` bundles the encoder + decoder ONNX files for that backbone.
|
| 27 |
+
|
| 28 |
+
| File | Backbone | Size | Notes |
|
| 29 |
+
|---|---|---|---|
|
| 30 |
+
| `mobile_sam_20230629.zip` | MobileSAM | 35 MB | Smallest — best for mobile / low-power |
|
| 31 |
+
| `mobile_sam_20230629_quant.zip` | MobileSAM | 10.5 MB | Quantized MobileSAM |
|
| 32 |
+
| `sam_vit_b_01ec64.zip` | ViT-B | 332 MB | Base |
|
| 33 |
+
| `sam_vit_b_01ec64_quant.zip` | ViT-B | 72 MB | Quantized base |
|
| 34 |
+
| `sam_vit_l_0b3195.zip` | ViT-L | 1.1 GB | Large |
|
| 35 |
+
| `sam_vit_l_0b3195_quant.zip` | ViT-L | 213 MB | Quantized large |
|
| 36 |
+
| `sam_vit_h_4b8939.zip` | ViT-H | 2.3 GB | Huge — best quality |
|
| 37 |
+
| `sam_vit_h_4b8939_quant.zip` | ViT-H | 422 MB | Quantized huge |
|
| 38 |
+
|
| 39 |
+
## Quick start
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
pip install huggingface_hub onnxruntime
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from huggingface_hub import hf_hub_download
|
| 47 |
+
import zipfile, onnxruntime as ort
|
| 48 |
+
|
| 49 |
+
zip_path = hf_hub_download(repo_id="vietanhdev/segment-anything-onnx-models",
|
| 50 |
+
filename="sam_vit_b_01ec64_quant.zip")
|
| 51 |
+
with zipfile.ZipFile(zip_path) as z:
|
| 52 |
+
z.extractall("./sam_vit_b_quant")
|
| 53 |
+
|
| 54 |
+
session = ort.InferenceSession("./sam_vit_b_quant/encoder.onnx",
|
| 55 |
+
providers=["CPUExecutionProvider"])
|
| 56 |
+
# Inspect expected inputs:
|
| 57 |
+
print([(i.name, i.shape, i.type) for i in session.get_inputs()])
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
For the full image → mask pipeline (encoder + decoder + prompt handling), see how AnyLabeling wires it: <https://github.com/vietanhdev/anylabeling>
|
| 61 |
+
|
| 62 |
+
## Use with AnyLabeling
|
| 63 |
+
|
| 64 |
+
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.
|
| 65 |
+
|
| 66 |
+
## Source weights
|
| 67 |
+
|
| 68 |
+
- Original SAM weights & license: <https://github.com/facebookresearch/segment-anything>
|
| 69 |
+
- MobileSAM: <https://github.com/ChaoningZhang/MobileSAM>
|
| 70 |
+
|
| 71 |
+
This repo redistributes the same weights in ONNX format. License unchanged from upstream releases (Apache 2.0).
|
| 72 |
+
|
| 73 |
+
## Citation
|
| 74 |
+
|
| 75 |
+
```bibtex
|
| 76 |
+
@misc{nguyen2026sam_onnx,
|
| 77 |
+
author = {Nguyen, Viet-Anh and {Neural Research Lab}},
|
| 78 |
+
title = {Segment Anything ONNX Models},
|
| 79 |
+
year = {2026},
|
| 80 |
+
url = {https://huggingface.co/vietanhdev/segment-anything-onnx-models}
|
| 81 |
+
}
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
For the underlying model, cite Meta's original SAM paper:
|
| 85 |
+
|
| 86 |
+
```bibtex
|
| 87 |
+
@article{kirillov2023sam,
|
| 88 |
+
title = {Segment Anything},
|
| 89 |
+
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},
|
| 90 |
+
journal = {arXiv:2304.02643},
|
| 91 |
+
year = {2023}
|
| 92 |
+
}
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Acknowledgments
|
| 96 |
+
|
| 97 |
+
Thanks to Meta AI Research for releasing the SAM family, and to the MobileSAM team for their efficient distillation. This repo packages their work for edge inference.
|
|
|
|
|
|
|
|
|
|
|
|