Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: facebook/sam2.1-hiera-tiny
|
| 4 |
+
tags:
|
| 5 |
+
- segment-anything
|
| 6 |
+
- onnx
|
| 7 |
+
- mobile
|
| 8 |
+
- image-segmentation
|
| 9 |
+
library_name: onnx
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# SAM 2.1 hiera-tiny β split ONNX (w8a8), multimask decoder
|
| 13 |
+
|
| 14 |
+
Repackaged for **on-device, CPU-only** tap-to-segment in
|
| 15 |
+
[DreamUI](https://github.com/AbrahamPaulJ/dreamui). Derived from Qualcomm AI Hub's
|
| 16 |
+
[Segment-Anything-Model-2](https://huggingface.co/qualcomm/Segment-Anything-Model-2)
|
| 17 |
+
w8a8 ONNX release (v0.59.0), which is itself an export of Meta's
|
| 18 |
+
[SAM 2.1 hiera-tiny](https://github.com/facebookresearch/sam2).
|
| 19 |
+
|
| 20 |
+
`sam2-split-w8a8.zip` (86,835,041 bytes) contains six flat files β each `.onnx`
|
| 21 |
+
references its `.data` by bare filename, so they must extract to one directory:
|
| 22 |
+
|
| 23 |
+
| File | Inputs β outputs | Runs |
|
| 24 |
+
|---|---|---|
|
| 25 |
+
| `trunk.onnx` / `.data` | `image` β embeddings, high-res features, pix_feat | once per image |
|
| 26 |
+
| `prompt.onnx` / `.data` | `unnorm_coords`, `labels` β `sparse_embedding` | once per tap (3 KB) |
|
| 27 |
+
| `decoder.onnx` / `.data` | embeddings + `sparse_embedding` β `masks`, `scores` | once per tap |
|
| 28 |
+
|
| 29 |
+
## Two changes from the AI Hub release
|
| 30 |
+
|
| 31 |
+
**1. The encoder is split into trunk + prompt.** AI Hub fuses the prompt encoder into the
|
| 32 |
+
image encoder, so a naive pipeline re-runs a 33.5M-parameter trunk on every click. The
|
| 33 |
+
trunk's outputs are bit-identical across clicks β only `sparse_embedding` varies β so
|
| 34 |
+
cutting at that seam turns ~817 ms per tap into ~817 ms per *image* plus ~28 ms per tap
|
| 35 |
+
(measured, Snapdragon 8 Elite, CPU EP, 4 threads).
|
| 36 |
+
|
| 37 |
+
**2. The decoder emits all four mask tokens.** The upstream export computes
|
| 38 |
+
`masks [1,4,256,256]` and slices `[0:1]`. Token 0 is the *single-mask* head, which blends
|
| 39 |
+
the competing interpretations of an ambiguous point prompt and visibly bleeds past object
|
| 40 |
+
boundaries; tokens 1β3 are the real granularity candidates. The `Slice` node's `ends` is
|
| 41 |
+
widened `1 β 4`. The trailing `QuantizeLinear` is untouched, so masks remain `uint8` on
|
| 42 |
+
the same scale/zero-point (0.3612250089645386 / 165) β only the channel count changes.
|
| 43 |
+
|
| 44 |
+
Measured on a 512Γ512 fixture, five clicks: token 3 was tighter than token 0 at **every**
|
| 45 |
+
click (25β55% smaller area) while the model's own IoU head rated the two within 0.04.
|
| 46 |
+
|
| 47 |
+
## Verified, not assumed
|
| 48 |
+
|
| 49 |
+
- Decoder **channel 0 is bit-identical** to the stock AI Hub decoder at all five clicks.
|
| 50 |
+
- `trunk + prompt + decoder` is **bit-identical** to `encoder + decoder` at all five clicks.
|
| 51 |
+
|
| 52 |
+
## Usage notes
|
| 53 |
+
|
| 54 |
+
- β **`unnorm_coords` wants NORMALISED coordinates**, in `[0, 1]`, despite the name.
|
| 55 |
+
Pixel coordinates return a confidently misplaced mask.
|
| 56 |
+
- β **Label *values* are ignored** by this export β only whether the second label is `-1`
|
| 57 |
+
(marking the second point slot unused) matters. There are no negative/background points.
|
| 58 |
+
- β **Blur the logits before thresholding.** Raw thresholding produces heavy
|
| 59 |
+
salt-and-pepper stipple along soft boundaries β checkerboard artifacting from the mask
|
| 60 |
+
decoder's transposed convolutions, present in the float export too. A 3Γ3 box blur on
|
| 61 |
+
the 256Γ256 logit field cuts it ~10Γ.
|
| 62 |
+
|
| 63 |
+
Quantization parameters for every tensor are in the AI Hub bundle's `metadata.json`.
|
| 64 |
+
|
| 65 |
+
## Licence
|
| 66 |
+
|
| 67 |
+
Apache 2.0, inherited from `facebookresearch/sam2`. Redistributed with attribution to
|
| 68 |
+
Meta AI (original model) and Qualcomm AI Hub (the ONNX export these files derive from).
|