vccarvalho11 commited on
Commit
6b7e488
·
verified ·
1 Parent(s): 03e185e

Upload sam2.1-hiera-tiny ONNX model

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ vision_encoder.onnx_data filter=lfs diff=lfs merge=lfs -text
37
+ prompt_encoder_mask_decoder.onnx_data filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: onnx
3
+ tags:
4
+ - sam2
5
+ - image-segmentation
6
+ - promptable-segmentation
7
+ - vision
8
+ - onnx
9
+ - inference4j
10
+ license: apache-2.0
11
+ pipeline_tag: mask-generation
12
+ ---
13
+
14
+ # SAM 2.1 Hiera Tiny — ONNX
15
+
16
+ FP32 ONNX export of [facebook/sam2.1-hiera-tiny](https://huggingface.co/facebook/sam2.1-hiera-tiny), split into an image encoder and a prompt encoder/mask decoder for point- and box-prompted image segmentation. The ONNX graphs are mirrored unchanged from the [onnx-community export](https://huggingface.co/onnx-community/sam2.1-hiera-tiny-ONNX).
17
+
18
+ Mirrored for use with [inference4j](https://github.com/inference4j/inference4j), an inference-only AI library for Java.
19
+
20
+ ## Original Source
21
+
22
+ - **Repository:** [Meta (ONNX export by onnx-community)](https://huggingface.co/facebook/sam2.1-hiera-tiny)
23
+ - **License:** apache-2.0
24
+
25
+ ## Usage with inference4j
26
+
27
+ ```java
28
+ try (Sam2Segmenter segmenter = Sam2Segmenter.builder().build()) {
29
+ SegmentationMask mask = segmenter.segment(
30
+ Path.of("photo.jpg"),
31
+ List.of(new PromptPoint(320, 240, true)));
32
+ ImageIO.write(mask.toImage(), "png", Path.of("mask.png").toFile());
33
+ }
34
+ ```
35
+
36
+ ## Model Details
37
+
38
+ | Property | Value |
39
+ |----------|-------|
40
+ | Architecture | SAM 2.1 Hiera Tiny |
41
+ | Task | Promptable image segmentation |
42
+ | Graphs | `vision_encoder.onnx` and `prompt_encoder_mask_decoder.onnx` (opset 18, FP32) |
43
+ | External data | Each graph loads its matching `.onnx_data` sidecar from the same directory |
44
+ | Image input | `pixel_values`: `[batch, 3, 1024, 1024]` float32, RGB |
45
+ | Image preprocessing | Resize to 1024 x 1024 without preserving aspect ratio; rescale by 1/255; ImageNet mean/std normalization |
46
+ | Prompts | Point coordinates and boxes use the 1024 x 1024 input coordinate space |
47
+ | Mask output | `pred_masks`: `[batch, prompts, 3, 256, 256]` float32 low-resolution logits |
48
+ | Mask selection | Choose one of three candidate masks using `iou_scores` |
49
+ | Refinement | No previous-mask (`mask_input`) input; iterative mask refinement is not supported by this export |
50
+
51
+ ## License
52
+
53
+ The original SAM 2.1 model and weights are licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). Original model by [Meta](https://huggingface.co/facebook/sam2.1-hiera-tiny); ONNX conversion by [onnx-community](https://huggingface.co/onnx-community/sam2.1-hiera-tiny-ONNX).
54
+
55
+ ## Files
56
+
57
+ The FP32 model remains split into two ONNX graphs and their external-data sidecars:
58
+
59
+ - `vision_encoder.onnx` + `vision_encoder.onnx_data`
60
+ - `prompt_encoder_mask_decoder.onnx` + `prompt_encoder_mask_decoder.onnx_data`
61
+
62
+ All four files must remain in the same directory. The sidecars are deliberately not
63
+ folded into the graph files.
64
+
65
+ ## Prompt Encoding
66
+
67
+ - Foreground point label: `1`
68
+ - Background point label: `0`
69
+ - Padding point label: `-10`
70
+ - Box layout: `(x1, y1, x2, y2)`
71
+
72
+ Coordinates are expressed in the resized 1024 x 1024 image space. See the source
73
+ `processor_config.json` for processor defaults and the inference4j wrapper for conversion
74
+ from original-image coordinates.
75
+
76
+ ## Outputs
77
+
78
+ The decoder returns three candidate low-resolution mask logits per prompt, their
79
+ `iou_scores`, and `object_score_logits`. Resize the selected logits to the original image
80
+ size and threshold at zero to obtain a binary mask.
81
+
config.json ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Sam2Model"
4
+ ],
5
+ "dtype": "float32",
6
+ "enable_occlusion_spatial_embedding": true,
7
+ "enable_temporal_pos_encoding_for_object_pointers": true,
8
+ "image_size": 1024,
9
+ "initializer_range": 0.02,
10
+ "mask_decoder_config": {
11
+ "attention_downsample_rate": 2,
12
+ "dtype": "float32",
13
+ "dynamic_multimask_stability_delta": 0.05,
14
+ "dynamic_multimask_stability_thresh": 0.98,
15
+ "dynamic_multimask_via_stability": true,
16
+ "hidden_act": "gelu",
17
+ "hidden_size": 256,
18
+ "iou_head_depth": 3,
19
+ "iou_head_hidden_dim": 256,
20
+ "mlp_dim": 2048,
21
+ "model_type": "",
22
+ "num_attention_heads": 8,
23
+ "num_hidden_layers": 2,
24
+ "num_multimask_outputs": 3
25
+ },
26
+ "mask_downsampler_embed_dim": 256,
27
+ "mask_downsampler_hidden_act": "gelu",
28
+ "mask_downsampler_kernel_size": 3,
29
+ "mask_downsampler_padding": 1,
30
+ "mask_downsampler_stride": 2,
31
+ "mask_downsampler_total_stride": 16,
32
+ "max_object_pointers_in_encoder": 16,
33
+ "memory_attention_downsample_rate": 1,
34
+ "memory_attention_dropout": 0.1,
35
+ "memory_attention_feed_forward_hidden_act": "relu",
36
+ "memory_attention_feed_forward_hidden_size": 2048,
37
+ "memory_attention_hidden_size": 256,
38
+ "memory_attention_num_attention_heads": 1,
39
+ "memory_attention_num_layers": 4,
40
+ "memory_attention_rope_dropout": 0.1,
41
+ "memory_attention_rope_feat_sizes": [
42
+ 64,
43
+ 64
44
+ ],
45
+ "memory_attention_rope_theta": 10000,
46
+ "memory_encoder_hidden_size": 256,
47
+ "memory_encoder_output_channels": 64,
48
+ "memory_fuser_embed_dim": 256,
49
+ "memory_fuser_hidden_act": "gelu",
50
+ "memory_fuser_intermediate_dim": 1024,
51
+ "memory_fuser_kernel_size": 7,
52
+ "memory_fuser_layer_scale_init_value": 1e-06,
53
+ "memory_fuser_num_layers": 2,
54
+ "memory_fuser_padding": 3,
55
+ "model_type": "sam2",
56
+ "multimask_max_pt_num": 1,
57
+ "multimask_min_pt_num": 0,
58
+ "multimask_output_for_tracking": true,
59
+ "multimask_output_in_sam": true,
60
+ "num_maskmem": 7,
61
+ "prompt_encoder_config": {
62
+ "dtype": "float32",
63
+ "hidden_act": "gelu",
64
+ "hidden_size": 256,
65
+ "image_size": 1024,
66
+ "layer_norm_eps": 1e-06,
67
+ "mask_input_channels": 16,
68
+ "model_type": "",
69
+ "num_point_embeddings": 4,
70
+ "patch_size": 16,
71
+ "scale": 1
72
+ },
73
+ "sigmoid_bias_for_mem_enc": -10.0,
74
+ "sigmoid_scale_for_mem_enc": 20.0,
75
+ "transformers_version": "5.0.0.dev0",
76
+ "vision_config": {
77
+ "backbone_channel_list": [
78
+ 768,
79
+ 384,
80
+ 192,
81
+ 96
82
+ ],
83
+ "backbone_config": {
84
+ "_name_or_path": "",
85
+ "add_cross_attention": false,
86
+ "architectures": null,
87
+ "bad_words_ids": null,
88
+ "begin_suppress_tokens": null,
89
+ "blocks_per_stage": [
90
+ 1,
91
+ 2,
92
+ 7,
93
+ 2
94
+ ],
95
+ "bos_token_id": null,
96
+ "chunk_size_feed_forward": 0,
97
+ "cross_attention_hidden_size": null,
98
+ "decoder_start_token_id": null,
99
+ "diversity_penalty": 0.0,
100
+ "do_sample": false,
101
+ "dtype": null,
102
+ "early_stopping": false,
103
+ "embed_dim_per_stage": [
104
+ 96,
105
+ 192,
106
+ 384,
107
+ 768
108
+ ],
109
+ "encoder_no_repeat_ngram_size": 0,
110
+ "eos_token_id": null,
111
+ "exponential_decay_length_penalty": null,
112
+ "finetuning_task": null,
113
+ "forced_bos_token_id": null,
114
+ "forced_eos_token_id": null,
115
+ "global_attention_blocks": [
116
+ 5,
117
+ 7,
118
+ 9
119
+ ],
120
+ "hidden_act": "gelu",
121
+ "hidden_size": 96,
122
+ "id2label": {
123
+ "0": "LABEL_0",
124
+ "1": "LABEL_1"
125
+ },
126
+ "image_size": [
127
+ 1024,
128
+ 1024
129
+ ],
130
+ "initializer_range": 0.02,
131
+ "is_decoder": false,
132
+ "is_encoder_decoder": false,
133
+ "label2id": {
134
+ "LABEL_0": 0,
135
+ "LABEL_1": 1
136
+ },
137
+ "layer_norm_eps": 1e-06,
138
+ "length_penalty": 1.0,
139
+ "max_length": 20,
140
+ "min_length": 0,
141
+ "mlp_ratio": 4.0,
142
+ "model_type": "sam2_hiera_det_model",
143
+ "no_repeat_ngram_size": 0,
144
+ "num_attention_heads": 1,
145
+ "num_attention_heads_per_stage": [
146
+ 1,
147
+ 2,
148
+ 4,
149
+ 8
150
+ ],
151
+ "num_beam_groups": 1,
152
+ "num_beams": 1,
153
+ "num_channels": 3,
154
+ "num_query_pool_stages": 3,
155
+ "num_return_sequences": 1,
156
+ "output_attentions": false,
157
+ "output_hidden_states": false,
158
+ "output_scores": false,
159
+ "pad_token_id": null,
160
+ "patch_kernel_size": [
161
+ 7,
162
+ 7
163
+ ],
164
+ "patch_padding": [
165
+ 3,
166
+ 3
167
+ ],
168
+ "patch_stride": [
169
+ 4,
170
+ 4
171
+ ],
172
+ "prefix": null,
173
+ "problem_type": null,
174
+ "pruned_heads": {},
175
+ "query_stride": [
176
+ 2,
177
+ 2
178
+ ],
179
+ "remove_invalid_values": false,
180
+ "repetition_penalty": 1.0,
181
+ "return_dict": true,
182
+ "return_dict_in_generate": false,
183
+ "sep_token_id": null,
184
+ "suppress_tokens": null,
185
+ "task_specific_params": null,
186
+ "temperature": 1.0,
187
+ "tf_legacy_loss": false,
188
+ "tie_encoder_decoder": false,
189
+ "tie_word_embeddings": true,
190
+ "tokenizer_class": null,
191
+ "top_k": 50,
192
+ "top_p": 1.0,
193
+ "torchscript": false,
194
+ "typical_p": 1.0,
195
+ "use_bfloat16": false,
196
+ "window_positional_embedding_background_size": [
197
+ 7,
198
+ 7
199
+ ],
200
+ "window_size_per_stage": [
201
+ 8,
202
+ 4,
203
+ 14,
204
+ 7
205
+ ]
206
+ },
207
+ "backbone_feature_sizes": [
208
+ [
209
+ 256,
210
+ 256
211
+ ],
212
+ [
213
+ 128,
214
+ 128
215
+ ],
216
+ [
217
+ 64,
218
+ 64
219
+ ]
220
+ ],
221
+ "dtype": "float32",
222
+ "fpn_hidden_size": 256,
223
+ "fpn_kernel_size": 1,
224
+ "fpn_padding": 0,
225
+ "fpn_stride": 1,
226
+ "fpn_top_down_levels": [
227
+ 2,
228
+ 3
229
+ ],
230
+ "hidden_act": "gelu",
231
+ "initializer_range": 0.02,
232
+ "layer_norm_eps": 1e-06,
233
+ "model_type": "sam2_vision_model",
234
+ "num_feature_levels": 3
235
+ },
236
+ "transformers.js_config": {
237
+ "use_external_data_format": true
238
+ }
239
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": null,
3
+ "data_format": "channels_first",
4
+ "default_to_square": true,
5
+ "device": null,
6
+ "disable_grouping": null,
7
+ "do_center_crop": null,
8
+ "do_convert_rgb": true,
9
+ "do_normalize": true,
10
+ "do_pad": null,
11
+ "do_rescale": true,
12
+ "do_resize": true,
13
+ "image_mean": [
14
+ 0.485,
15
+ 0.456,
16
+ 0.406
17
+ ],
18
+ "image_processor_type": "Sam2ImageProcessorFast",
19
+ "image_seq_length": null,
20
+ "image_std": [
21
+ 0.229,
22
+ 0.224,
23
+ 0.225
24
+ ],
25
+ "input_data_format": null,
26
+ "mask_size": {
27
+ "height": 256,
28
+ "width": 256
29
+ },
30
+ "pad_size": null,
31
+ "processor_class": "Sam2VideoProcessor",
32
+ "resample": 2,
33
+ "rescale_factor": 0.00392156862745098,
34
+ "return_tensors": null,
35
+ "size": {
36
+ "height": 1024,
37
+ "width": 1024
38
+ }
39
+ }
processor_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "crop_size": null,
4
+ "data_format": "channels_first",
5
+ "default_to_square": true,
6
+ "device": null,
7
+ "disable_grouping": null,
8
+ "do_center_crop": null,
9
+ "do_convert_rgb": true,
10
+ "do_normalize": true,
11
+ "do_pad": null,
12
+ "do_rescale": true,
13
+ "do_resize": true,
14
+ "image_mean": [
15
+ 0.485,
16
+ 0.456,
17
+ 0.406
18
+ ],
19
+ "image_processor_type": "Sam2ImageProcessorFast",
20
+ "image_seq_length": null,
21
+ "image_std": [
22
+ 0.229,
23
+ 0.224,
24
+ 0.225
25
+ ],
26
+ "input_data_format": null,
27
+ "mask_size": {
28
+ "height": 256,
29
+ "width": 256
30
+ },
31
+ "pad_size": null,
32
+ "processor_class": "Sam2Processor",
33
+ "resample": 2,
34
+ "rescale_factor": 0.00392156862745098,
35
+ "return_tensors": null,
36
+ "size": {
37
+ "height": 1024,
38
+ "width": 1024
39
+ }
40
+ },
41
+ "point_pad_value": -10,
42
+ "processor_class": "Sam2Processor",
43
+ "target_size": 1024
44
+ }
prompt_encoder_mask_decoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:874414704c5d686db7d206a35f6e15d26563d50c8c4468fccc6739bd7e491dcf
3
+ size 213114
prompt_encoder_mask_decoder.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e9874d900dd4134ed60eab1e97910327c2419e0b2954485d8fd6e7f1a1470f47
3
+ size 20958208
vision_encoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f30aacd3aaefbca81a0b7fe4c1fc96345570ea0a6f80ced599493d1b3be2e8c
3
+ size 354238
vision_encoder.onnx_data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e83df9866a5afe68ea7f0f721f18f65137fc3acbf0da1c74e946d363e09c69cc
3
+ size 134084864