YanNoun commited on
Commit
459dd40
·
verified ·
1 Parent(s): 55c509b

SAM 3 decoder with instance outputs (rank-based top-K selection)

Browse files
README.md CHANGED
@@ -38,14 +38,16 @@ the **SAM License** (`sam3/LICENSE`), which must accompany any redistribution.
38
  | `onnx/sam3-image-encoder-1008-fp16.onnx` (+ `.onnx.data`) | Image encoder. `pixel_values` [1,3,1008,1008] fp16 (RGB / 255, mean 0.5, std 0.5) → `fpn_feat_0..2` [1,256,288²/144²/72²] (+ constant `fpn_pos_0..2`) |
39
  | `onnx/sam3-text-encoder-ctx32-fp16.onnx` | Text encoder. `input_ids` [N,32] int64 (CLIP BPE, start 49406, end 49407, padded with 0), `attention_mask` [N,32] int64 → `text_features` [32,N,256], `text_mask` [N,32] bool (True = padding) |
40
  | `onnx/sam3-decoder-1008-p16-top64-fp16.onnx` | Prompted decoder, 16 prompt slots (pad by repeating a prompt). `fpn_feat_0..2`, `text_features` [32,16,256], `text_mask` [16,32] bool → `prompt_scores` [16,288,288] (per prompt: max over the detections of score × mask, and the semantic map × presence), `scores` [16,200], `boxes` [16,200,4] (cx, cy, w, h normalised) |
 
41
  | `coreml/sam3-image-encoder-1008-fp16.mlpackage` | Image encoder, Core ML ML program (macOS 15+); same interface, outputs `fpn_feat_0..2` |
42
  | `coreml/sam3-decoder-1008-p16-top64-fp16.mlpackage` | Prompted decoder, Core ML; as the ONNX one with `text_mask` as fp16 (1 = padding) |
 
43
  | `embeddings/sam3-text-ctx32-fp16.npz` | Precomputed prompts: `prompts` [N], `features` [N,32,256], `mask` [N,32] |
44
  | `tokenizer/sam3-clip-bpe-tokenizer.json` | CLIP BPE tokenizer (Hugging Face `tokenizers`) |
45
 
46
  Naming: `<model>-<component>-<input size>[-<variant>]-<precision>.<format>`
47
  (`p16`: 16 prompt slots, `top64`: masks computed for the 64 best detections
48
- per prompt, `ctx32`: 32 text tokens).
49
 
50
  ### Export
51
 
@@ -55,7 +57,10 @@ Exported with the Ultralytics SAM 3 implementation and the export patches of
55
  64 best detections only, window partitioning and mask products rewritten for
56
  Core ML (rank ≤ 5, matmul), opset 18. The Core ML encoder is ONNX Runtime's
57
  ML-program conversion with its constants moved to the weight blob; the Core
58
- ML decoder is converted from PyTorch with coremltools.
 
 
 
59
 
60
  On an Apple M5 Pro (Core ML, CPU + GPU): encoder 0.42 s and decoder 0.8 s
61
  per image; label maps agree with the PyTorch reference (transformers
 
38
  | `onnx/sam3-image-encoder-1008-fp16.onnx` (+ `.onnx.data`) | Image encoder. `pixel_values` [1,3,1008,1008] fp16 (RGB / 255, mean 0.5, std 0.5) → `fpn_feat_0..2` [1,256,288²/144²/72²] (+ constant `fpn_pos_0..2`) |
39
  | `onnx/sam3-text-encoder-ctx32-fp16.onnx` | Text encoder. `input_ids` [N,32] int64 (CLIP BPE, start 49406, end 49407, padded with 0), `attention_mask` [N,32] int64 → `text_features` [32,N,256], `text_mask` [N,32] bool (True = padding) |
40
  | `onnx/sam3-decoder-1008-p16-top64-fp16.onnx` | Prompted decoder, 16 prompt slots (pad by repeating a prompt). `fpn_feat_0..2`, `text_features` [32,16,256], `text_mask` [16,32] bool → `prompt_scores` [16,288,288] (per prompt: max over the detections of score × mask, and the semantic map × presence), `scores` [16,200], `boxes` [16,200,4] (cx, cy, w, h normalised) |
41
+ | `onnx/sam3-decoder-1008-p16-top64-inst-fp16.onnx` | Prompted decoder with instances (used by OpenSfM since this revision): as above, but → `prompt_scores` [16,288,288], `instance_index` [16,288,288] (per prompt and pixel, the detection 0..63 whose mask wins the pixel, -1: none), `instance_scores` [16,64] (the 64 best detections' scores, 0 below 0.3), `instance_boxes` [16,64,4] (cx, cy, w, h normalised) |
42
  | `coreml/sam3-image-encoder-1008-fp16.mlpackage` | Image encoder, Core ML ML program (macOS 15+); same interface, outputs `fpn_feat_0..2` |
43
  | `coreml/sam3-decoder-1008-p16-top64-fp16.mlpackage` | Prompted decoder, Core ML; as the ONNX one with `text_mask` as fp16 (1 = padding) |
44
+ | `coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage` | Prompted decoder with instances, Core ML; as the ONNX one with `text_mask` as fp16 |
45
  | `embeddings/sam3-text-ctx32-fp16.npz` | Precomputed prompts: `prompts` [N], `features` [N,32,256], `mask` [N,32] |
46
  | `tokenizer/sam3-clip-bpe-tokenizer.json` | CLIP BPE tokenizer (Hugging Face `tokenizers`) |
47
 
48
  Naming: `<model>-<component>-<input size>[-<variant>]-<precision>.<format>`
49
  (`p16`: 16 prompt slots, `top64`: masks computed for the 64 best detections
50
+ per prompt, `inst`: instance outputs, `ctx32`: 32 text tokens).
51
 
52
  ### Export
53
 
 
57
  64 best detections only, window partitioning and mask products rewritten for
58
  Core ML (rank ≤ 5, matmul), opset 18. The Core ML encoder is ONNX Runtime's
59
  ML-program conversion with its constants moved to the weight blob; the Core
60
+ ML decoder is converted from PyTorch with coremltools. The `inst` decoders
61
+ select the 64 best detections with a one-hot matmul over the detections'
62
+ ranks rather than `topk`, whose indices come out wrong on Apple GPUs (the
63
+ older decoders lose detections there).
64
 
65
  On an Apple M5 Pro (Core ML, CPU + GPU): encoder 0.42 s and decoder 0.8 s
66
  per image; label maps agree with the PyTorch reference (transformers
manifest.json CHANGED
@@ -18,6 +18,7 @@
18
  0.5
19
  ],
20
  "mask_size": 288,
 
21
  "components": {
22
  "image_encoder": {
23
  "onnx": "sam3/onnx/sam3-image-encoder-1008-fp16.onnx",
@@ -27,8 +28,8 @@
27
  "onnx": "sam3/onnx/sam3-text-encoder-ctx32-fp16.onnx"
28
  },
29
  "decoder": {
30
- "onnx": "sam3/onnx/sam3-decoder-1008-p16-top64-fp16.onnx",
31
- "coreml": "sam3/coreml/sam3-decoder-1008-p16-top64-fp16.mlpackage"
32
  },
33
  "embeddings": "sam3/embeddings/sam3-text-ctx32-fp16.npz",
34
  "tokenizer": "sam3/tokenizer/sam3-clip-bpe-tokenizer.json"
@@ -52,6 +53,18 @@
52
  "size": 617,
53
  "sha256": "3c6a9982e2ebdb3c8376794dd353f1001fcbf60b7deee420248cd9b742d71fa2"
54
  },
 
 
 
 
 
 
 
 
 
 
 
 
55
  "sam3/coreml/sam3-image-encoder-1008-fp16.mlpackage/Data/com.apple.CoreML/model.mlmodel": {
56
  "size": 839846,
57
  "sha256": "5081259d8feb00e8a992b2527881f1feb4e75667f107c31b40068c059585ab9e"
@@ -76,6 +89,10 @@
76
  "size": 65438647,
77
  "sha256": "37ae92966adf656e2091db8ba1378c1fae66bfd932b8d2f7c0eca3de30fd7042"
78
  },
 
 
 
 
79
  "sam3/onnx/sam3-image-encoder-1008-fp16.onnx": {
80
  "size": 4687059,
81
  "sha256": "ff76682f4eba9cf81d8a324ba1c24a4c256bc2a69d60cbce15ef89eeaedcce87"
 
18
  0.5
19
  ],
20
  "mask_size": 288,
21
+ "instance_slots": 64,
22
  "components": {
23
  "image_encoder": {
24
  "onnx": "sam3/onnx/sam3-image-encoder-1008-fp16.onnx",
 
28
  "onnx": "sam3/onnx/sam3-text-encoder-ctx32-fp16.onnx"
29
  },
30
  "decoder": {
31
+ "onnx": "sam3/onnx/sam3-decoder-1008-p16-top64-inst-fp16.onnx",
32
+ "coreml": "sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage"
33
  },
34
  "embeddings": "sam3/embeddings/sam3-text-ctx32-fp16.npz",
35
  "tokenizer": "sam3/tokenizer/sam3-clip-bpe-tokenizer.json"
 
53
  "size": 617,
54
  "sha256": "3c6a9982e2ebdb3c8376794dd353f1001fcbf60b7deee420248cd9b742d71fa2"
55
  },
56
+ "sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Data/com.apple.CoreML/model.mlmodel": {
57
+ "size": 602309,
58
+ "sha256": "dfb4bfd3def82fe7bb1cce8efc948f02b5f9d2f81b12b8edac9a07f4b5692a60"
59
+ },
60
+ "sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Data/com.apple.CoreML/weights/weight.bin": {
61
+ "size": 414074752,
62
+ "sha256": "de8db5683944db17458d79c16b542b2b8d87517da56607e186585cabe15f288d"
63
+ },
64
+ "sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Manifest.json": {
65
+ "size": 617,
66
+ "sha256": "50591053c7e1f240ba758a2cf4f69b0b72bba216f3778a00f0d3dcb242ff4aaf"
67
+ },
68
  "sam3/coreml/sam3-image-encoder-1008-fp16.mlpackage/Data/com.apple.CoreML/model.mlmodel": {
69
  "size": 839846,
70
  "sha256": "5081259d8feb00e8a992b2527881f1feb4e75667f107c31b40068c059585ab9e"
 
89
  "size": 65438647,
90
  "sha256": "37ae92966adf656e2091db8ba1378c1fae66bfd932b8d2f7c0eca3de30fd7042"
91
  },
92
+ "sam3/onnx/sam3-decoder-1008-p16-top64-inst-fp16.onnx": {
93
+ "size": 65503726,
94
+ "sha256": "7c36e6423a1511e3ea9d6ef80b4e2005cfd0be3051defb73f06a1c5332c641de"
95
+ },
96
  "sam3/onnx/sam3-image-encoder-1008-fp16.onnx": {
97
  "size": 4687059,
98
  "sha256": "ff76682f4eba9cf81d8a324ba1c24a4c256bc2a69d60cbce15ef89eeaedcce87"
sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Data/com.apple.CoreML/model.mlmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfb4bfd3def82fe7bb1cce8efc948f02b5f9d2f81b12b8edac9a07f4b5692a60
3
+ size 602309
sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Data/com.apple.CoreML/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de8db5683944db17458d79c16b542b2b8d87517da56607e186585cabe15f288d
3
+ size 414074752
sam3/coreml/sam3-decoder-1008-p16-top64-inst-fp16.mlpackage/Manifest.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "1231DB19-631B-44E0-BBF6-7A7426D11D38": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "CoreML Model Weights",
7
+ "name": "weights",
8
+ "path": "com.apple.CoreML/weights"
9
+ },
10
+ "546A0BEF-1474-4ECC-9A11-0730DD94191A": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "CoreML Model Specification",
13
+ "name": "model.mlmodel",
14
+ "path": "com.apple.CoreML/model.mlmodel"
15
+ }
16
+ },
17
+ "rootModelIdentifier": "546A0BEF-1474-4ECC-9A11-0730DD94191A"
18
+ }
sam3/onnx/sam3-decoder-1008-p16-top64-inst-fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c36e6423a1511e3ea9d6ef80b4e2005cfd0be3051defb73f06a1c5332c641de
3
+ size 65503726