fernandotonon commited on
Commit
9156103
·
verified ·
1 Parent(s): 88e3bb2

Model card

Browse files
Files changed (1) hide show
  1. README.md +70 -0
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: onnx
4
+ pipeline_tag: mask-generation
5
+ tags:
6
+ - onnx
7
+ - segment-anything
8
+ - sam2
9
+ - mesh-segmentation
10
+ - qtmesheditor
11
+ base_model:
12
+ - facebook/sam2.1-hiera-small
13
+ ---
14
+
15
+ # SAM 2.1 (Hiera-Small) — ONNX export, image encoder + prompt decoder
16
+
17
+ **ONNX re-export of Meta's [SAM 2.1 Hiera-Small](https://github.com/facebookresearch/sam2)**
18
+ (*"SAM 2: Segment Anything in Images and Videos"*, Ravi et al. 2024 — Apache-2.0
19
+ code + Apache-2.0 weights). All credit for the model goes to Meta AI / FAIR.
20
+
21
+ Two graphs for **single-image** automatic mask generation (no video memory):
22
+ used by **[QtMeshEditor](https://github.com/fernandotonon/QtMeshEditor)**'s
23
+ generic part segmentation (#1179). It renders a mesh from many views, runs these
24
+ graphs on each render, and lifts the masks back onto the mesh. That is our own
25
+ C++ implementation of the SAMesh method, with local inference through ONNX
26
+ Runtime and no Python at runtime.
27
+
28
+ > The files QtMeshEditor downloads at runtime live in the shared
29
+ > [`fernandotonon/QtMeshEditor-models`](https://huggingface.co/fernandotonon/QtMeshEditor-models)
30
+ > repo under `segment/`. This repo is the standalone model card + mirror.
31
+
32
+ ## Files
33
+
34
+ | file | role | size |
35
+ |---|---|---|
36
+ | `sam2.1_hiera_small_encoder.onnx` | image encoder: `image[1,3,1024,1024]` (RGB, ImageNet mean/std normalised) → `image_embed[1,256,64,64]`, `high_res_feat0[1,32,256,256]`, `high_res_feat1[1,64,128,128]` (`no_mem_embed` already added) | 138 MB |
37
+ | `sam2.1_hiera_small_decoder.onnx` | prompt encoder + mask decoder: the three encoder outputs + `point_coords[B,N,2]` (pixels of the 1024 input frame) + `point_labels[B,N]` (1 = foreground, 0 = background, -1 = padding) → `mask_logits[B,3,256,256]` + `iou_scores[B,3]` (multimask output) | 21 MB |
38
+ | `LICENSE-SAM2.txt` | Apache-2.0 (Meta SAM 2) | |
39
+
40
+ `B` (prompts per run) and `N` (points per prompt) are dynamic. Upsample the
41
+ 256² logits to the image size bilinearly (align_corners = false) and threshold
42
+ at 0.
43
+
44
+ ## How it was exported
45
+
46
+ `scripts/export-sam2-onnx.py` in the QtMeshEditor repo (TorchScript exporter,
47
+ opset 17) from the official `sam2.1_hiera_small.pt` checkpoint, SAM 2 commit
48
+ `2b90b9f5`. The padding-point embedding is rewritten functionally (the
49
+ exporter otherwise emits `Add` nodes with empty inputs that only fail at ONNX
50
+ Runtime load time). The script refuses to finish unless:
51
+
52
+ - both graphs load in ONNX Runtime and produce finite outputs;
53
+ - on an 8×8 point grid over three mesh renders, every mask matches Meta's
54
+ `SAM2ImagePredictor` with IoU ≥ 0.99 (measured ≥ 0.9995) and every
55
+ predicted IoU score within 1e-3;
56
+ - the dynamic `B` / `N` shapes work.
57
+
58
+ ## Automatic mask generation (what QtMeshEditor does around it)
59
+
60
+ The reimplemented part of `SAM2AutomaticMaskGenerator`: a 16×16 prompt grid
61
+ restricted to the object's pixels, batches of 64 single-point prompts, keep
62
+ masks with predicted IoU ≥ 0.7 and stability ≥ 0.85 (logit offset 1.0), mask
63
+ NMS at IoU 0.7, drop masks under 0.1 % of the object. About 45–85 s per mesh
64
+ for 40 renders on an Apple M-series CPU.
65
+
66
+ ## Licence
67
+
68
+ Apache-2.0, as the original SAM 2 code and checkpoints. `LICENSE-SAM2.txt` is
69
+ Meta's licence text. These graphs are a format conversion of Meta's weights;
70
+ no fine-tuning.