vietanhdev commited on
Commit
6a3ac86
·
verified ·
1 Parent(s): 0544279

docs: rewrite model card with variants table, citation, AnyLabeling cross-link

Browse files
Files changed (1) hide show
  1. README.md +92 -106
README.md CHANGED
@@ -1,106 +1,92 @@
1
- ---
2
- license: apache-2.0
3
- tags:
4
- - image-segmentation
5
- - segment-anything
6
- - segment-anything-2
7
- - onnx
8
- - onnxruntime
9
- library_name: onnxruntime
10
- ---
11
-
12
- # Segment Anything 2.1 (SAM 2.1) — ONNX Models
13
-
14
- ONNX-exported versions of Meta's **Segment Anything Model 2.1 (SAM 2.1)** — an improved version of [SAM 2](https://github.com/facebookresearch/segment-anything-2) with better accuracy and robustness — ready for CPU/GPU inference with [ONNX Runtime](https://onnxruntime.ai/).
15
-
16
- These models are used by **[AnyLabeling](https://github.com/vietanhdev/anylabeling)** for AI-assisted image annotation, and exported by **[samexporter](https://github.com/vietanhdev/samexporter)**.
17
-
18
- ## Available Models
19
-
20
- | File | Variant | Notes |
21
- |------|---------|-------|
22
- | `sam2.1_hiera_tiny_20260221.zip` | SAM 2.1 Hiera-Tiny | Smallest, fastest |
23
- | `sam2.1_hiera_small_20260221.zip` | SAM 2.1 Hiera-Small | Good balance |
24
- | `sam2.1_hiera_base_plus_20260221.zip` | SAM 2.1 Hiera-Base+ | Higher accuracy |
25
- | `sam2.1_hiera_large_20260221.zip` | SAM 2.1 Hiera-Large | Most accurate |
26
-
27
- Each zip contains two ONNX files: an **encoder** (runs once per image) and a **decoder** (runs interactively for each prompt).
28
-
29
- ## What's Improved vs SAM 2?
30
-
31
- SAM 2.1 offers improved segmentation accuracy and better handling of edge cases compared to SAM 2. The ONNX conversion process is identical, and both use the same inference API.
32
-
33
- ## Prompt Types
34
-
35
- - **Point** (`+point` / `-point`): click to include/exclude regions
36
- - **Rectangle**: draw a bounding box around the target object
37
-
38
- ## Use with AnyLabeling (Recommended)
39
-
40
- [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.
41
-
42
- 1. Install: `pip install anylabeling`
43
- 2. Launch: `anylabeling`
44
- 3. Click the **Brain** button → select a **Segment Anything 2.1** model from the dropdown
45
- 4. Use point or rectangle prompts to segment objects
46
-
47
- [![AnyLabeling demo](https://user-images.githubusercontent.com/18329471/236625792-07f01838-3f69-48b0-a12e-30bad27bd921.gif)](https://github.com/vietanhdev/anylabeling)
48
-
49
- ## Use Programmatically with ONNX Runtime
50
-
51
- ```python
52
- import urllib.request, zipfile
53
- url = "https://huggingface.co/vietanhdev/segment-anything-2.1-onnx-models/resolve/main/sam2.1_hiera_tiny_20260221.zip"
54
- urllib.request.urlretrieve(url, "sam2.1_hiera_tiny.zip")
55
- with zipfile.ZipFile("sam2.1_hiera_tiny.zip") as z:
56
- z.extractall("sam2.1_hiera_tiny")
57
- ```
58
-
59
- Then use [samexporter](https://github.com/vietanhdev/samexporter)'s inference module:
60
-
61
- ```bash
62
- pip install samexporter
63
- python -m samexporter.inference \
64
- --encoder_model sam2.1_hiera_tiny/sam2.1_hiera_tiny.encoder.onnx \
65
- --decoder_model sam2.1_hiera_tiny/sam2.1_hiera_tiny.decoder.onnx \
66
- --image photo.jpg \
67
- --prompt prompt.json \
68
- --output result.png \
69
- --sam_variant sam2
70
- ```
71
-
72
- ## Re-export from Source
73
-
74
- To re-export or customize the models using [samexporter](https://github.com/vietanhdev/samexporter):
75
-
76
- ```bash
77
- pip install samexporter
78
- pip install git+https://github.com/facebookresearch/segment-anything-2.git
79
-
80
- # Download SAM 2.1 checkpoints
81
- bash download_all_models.sh
82
-
83
- # Export Tiny variant
84
- python -m samexporter.export_sam2 \
85
- --checkpoint original_models/sam2.1_hiera_tiny.pt \
86
- --output_encoder output_models/sam2.1_hiera_tiny.encoder.onnx \
87
- --output_decoder output_models/sam2.1_hiera_tiny.decoder.onnx \
88
- --model_type sam2.1_hiera_tiny
89
-
90
- # Or convert all SAM 2 and SAM 2.1 variants at once:
91
- bash convert_all_meta_sam2.sh
92
- ```
93
-
94
- ## Related Repositories
95
-
96
- | Repo | Description |
97
- |------|-------------|
98
- | [vietanhdev/samexporter](https://github.com/vietanhdev/samexporter) | Export scripts, inference code, conversion tools |
99
- | [vietanhdev/anylabeling](https://github.com/vietanhdev/anylabeling) | Desktop annotation app powered by these models |
100
- | [vietanhdev/segment-anything-2-onnx-models](https://huggingface.co/vietanhdev/segment-anything-2-onnx-models) | Original SAM 2 ONNX models |
101
- | [facebookresearch/segment-anything-2](https://github.com/facebookresearch/segment-anything-2) | Original SAM 2 / SAM 2.1 by Meta |
102
-
103
- ## License
104
-
105
- The ONNX models are derived from Meta's SAM 2.1, released under the **Apache 2.0** license.
106
- 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
+ - segment-anything-2
10
+ - segment-anything-2.1
11
+ - image-segmentation
12
+ - edge-ai
13
+ - anylabeling
14
+ authors:
15
+ - Viet-Anh Nguyen
16
+ ---
17
+
18
+ # Segment Anything 2.1 (SAM 2.1) — ONNX Models
19
+
20
+ ONNX exports of Meta's [SAM 2.1](https://github.com/facebookresearch/sam2) backbones — the maintenance release of SAM 2 — packaged for direct use with [`onnxruntime`](https://onnxruntime.ai) and [AnyLabeling](https://github.com/vietanhdev/anylabeling).
21
+
22
+ ## Why this repo exists
23
+
24
+ SAM 2.1 ships incremental quality improvements over SAM 2 with the same architecture and runtime cost. 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.
25
+
26
+ ## Variants
27
+
28
+ Each `.zip` bundles the encoder + decoder ONNX files for that backbone. The `_20260221` suffix is the export date.
29
+
30
+ | File | Backbone | Size |
31
+ |---|---|---|
32
+ | `sam2.1_hiera_tiny_20260221.zip` | Hiera-T | 111 MB |
33
+ | `sam2.1_hiera_small_20260221.zip` | Hiera-S | 136 MB |
34
+ | `sam2.1_hiera_base_plus_20260221.zip` | Hiera-B+ | 259 MB |
35
+ | `sam2.1_hiera_large_20260221.zip` | Hiera-L | 768 MB |
36
+
37
+ ## Quick start
38
+
39
+ ```bash
40
+ pip install huggingface_hub onnxruntime
41
+ ```
42
+
43
+ ```python
44
+ from huggingface_hub import hf_hub_download
45
+ import zipfile, onnxruntime as ort
46
+
47
+ zip_path = hf_hub_download(repo_id="vietanhdev/segment-anything-2.1-onnx-models",
48
+ filename="sam2.1_hiera_tiny_20260221.zip")
49
+ with zipfile.ZipFile(zip_path) as z:
50
+ z.extractall("./sam21_tiny")
51
+
52
+ enc = ort.InferenceSession("./sam21_tiny/encoder.onnx", providers=["CPUExecutionProvider"])
53
+ print([(i.name, i.shape, i.type) for i in enc.get_inputs()])
54
+ ```
55
+
56
+ For the full image → mask pipeline (encoder + decoder + prompt handling), see how AnyLabeling wires it: <https://github.com/vietanhdev/anylabeling>
57
+
58
+ ## Use with AnyLabeling
59
+
60
+ 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.
61
+
62
+ ## Source weights
63
+
64
+ Original SAM 2.1 weights and license: <https://github.com/facebookresearch/sam2>
65
+
66
+ This repo redistributes the same weights in ONNX format. License unchanged from upstream (Apache 2.0).
67
+
68
+ ## Citation
69
+
70
+ ```bibtex
71
+ @misc{nguyen2026sam21_onnx,
72
+ author = {Nguyen, Viet-Anh and {Neural Research Lab}},
73
+ title = {SAM 2.1 ONNX Models},
74
+ year = {2026},
75
+ url = {https://huggingface.co/vietanhdev/segment-anything-2.1-onnx-models}
76
+ }
77
+ ```
78
+
79
+ For the underlying model, cite Meta's SAM 2 paper (SAM 2.1 is a release of the same model family):
80
+
81
+ ```bibtex
82
+ @article{ravi2024sam2,
83
+ title = {SAM 2: Segment Anything in Images and Videos},
84
+ author = {Ravi, Nikhila and others},
85
+ journal = {arXiv:2408.00714},
86
+ year = {2024}
87
+ }
88
+ ```
89
+
90
+ ## Acknowledgments
91
+
92
+ Thanks to Meta AI Research for the SAM 2.x line. This repo packages their work for edge inference.