yujiepan commited on
Commit
6db29ac
·
verified ·
1 Parent(s): 8b252bb

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: text-generation
4
+ inference: true
5
+ widget:
6
+ - text: Hello!
7
+ example_title: Hello world
8
+ group: Python
9
+ base_model:
10
+ - facebook/sam3
11
+ ---
12
+
13
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [facebook/sam3](https://huggingface.co/facebook/sam3).
14
+
15
+ ### Example usage:
16
+
17
+ ```python
18
+ import requests
19
+ import torch
20
+ from PIL import Image
21
+ from transformers import Sam3Model, Sam3Processor
22
+ from transformers.models.sam3.modeling_sam3 import Sam3Config
23
+
24
+ model_id = "tiny-random/sam3"
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ model = Sam3Model.from_pretrained(model_id).to(device)
27
+ processor = Sam3Processor.from_pretrained(model_id)
28
+
29
+ kitchen_url = "http://images.cocodataset.org/val2017/000000136466.jpg"
30
+ kitchen_image = Image.open(requests.get(
31
+ kitchen_url, stream=True).raw).convert("RGB")
32
+ # Segment "handle" but exclude the oven handle using a negative box
33
+ text = "handle"
34
+ # Negative box covering oven handle area (xyxy): [40, 183, 318, 204]
35
+ oven_handle_box = [40, 183, 318, 204]
36
+ input_boxes = [[oven_handle_box]]
37
+ inputs = processor(
38
+ images=kitchen_image,
39
+ text=text,
40
+ input_boxes=input_boxes,
41
+ input_boxes_labels=[[0]], # 0 = negative (exclude this region)
42
+ return_tensors="pt"
43
+ ).to(device)
44
+ with torch.no_grad():
45
+ outputs = model(**inputs)
46
+ # Post-process results
47
+ results = processor.post_process_instance_segmentation(
48
+ outputs,
49
+ threshold=0.5,
50
+ mask_threshold=0.5,
51
+ target_sizes=inputs.get("original_sizes").tolist()
52
+ )[0]
53
+ print(results)
54
+ # This will segment pot handles but exclude the oven handle
55
+ ```
56
+
57
+ ### Codes to create this repo:
58
+
59
+ ```python
60
+ import json
61
+ from pathlib import Path
62
+
63
+ import accelerate
64
+ import torch
65
+ from huggingface_hub import file_exists, hf_hub_download
66
+ from transformers import (
67
+ AutoConfig,
68
+ AutoModelForCausalLM,
69
+ AutoProcessor,
70
+ GenerationConfig,
71
+ Sam3Processor,
72
+ set_seed,
73
+ )
74
+ from transformers.models.sam3.modeling_sam3 import Sam3Config, Sam3Model
75
+
76
+ source_model_id = "facebook/sam3"
77
+ save_folder = "/tmp/tiny-random/sam3"
78
+
79
+ processor = Sam3Processor.from_pretrained(
80
+ source_model_id, trust_remote_code=True)
81
+ processor.save_pretrained(save_folder)
82
+
83
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
84
+ config_json = json.load(f)
85
+ HIDDEN_SIZE = 16
86
+ INTERMEDIATE_SIZE = 32
87
+ NUM_ATTENTION_HEADS = 2
88
+ config_json['detector_config']['detr_decoder_config'].update({
89
+ 'hidden_size': HIDDEN_SIZE,
90
+ 'intermediate_size': INTERMEDIATE_SIZE,
91
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
92
+ })
93
+ config_json['detector_config']['detr_encoder_config'].update({
94
+ 'hidden_size': HIDDEN_SIZE,
95
+ 'intermediate_size': INTERMEDIATE_SIZE,
96
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
97
+ })
98
+ config_json['detector_config']['geometry_encoder_config'].update({
99
+ 'hidden_size': HIDDEN_SIZE,
100
+ 'intermediate_size': INTERMEDIATE_SIZE,
101
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
102
+ })
103
+ config_json['detector_config']['mask_decoder_config'].update({
104
+ 'hidden_size': HIDDEN_SIZE,
105
+ 'intermediate_size': INTERMEDIATE_SIZE,
106
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
107
+ })
108
+ config_json['detector_config']['text_config'].update({
109
+ 'hidden_size': HIDDEN_SIZE,
110
+ 'intermediate_size': INTERMEDIATE_SIZE,
111
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
112
+ 'projection_dim': HIDDEN_SIZE,
113
+ 'num_hidden_layers': 2,
114
+ })
115
+ config_json['detector_config']['vision_config']['backbone_config'].update({
116
+ 'hidden_size': HIDDEN_SIZE,
117
+ 'intermediate_size': INTERMEDIATE_SIZE,
118
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
119
+ 'fpn_hidden_size': HIDDEN_SIZE,
120
+ 'global_attn_indexes': [1, 3, 5, 7],
121
+ 'num_hidden_layers': 8,
122
+ })
123
+ config_json['detector_config']['vision_config'].update({
124
+ 'fpn_hidden_size': HIDDEN_SIZE,
125
+ })
126
+ config_json['tracker_config']['mask_decoder_config'].update({
127
+ 'hidden_size': HIDDEN_SIZE,
128
+ 'iou_head_hidden_dim': HIDDEN_SIZE,
129
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
130
+ })
131
+ config_json['tracker_config'].update({
132
+ 'mask_downsampler_embed_dim': HIDDEN_SIZE,
133
+ 'memory_attention_feed_forward_hidden_size': HIDDEN_SIZE,
134
+ 'memory_attention_hidden_size': HIDDEN_SIZE,
135
+ 'memory_encoder_hidden_size': HIDDEN_SIZE,
136
+ 'memory_fuser_embed_dim': HIDDEN_SIZE,
137
+ 'memory_fuser_intermediate_dim': INTERMEDIATE_SIZE,
138
+ })
139
+ config_json['tracker_config']['prompt_encoder_config'].update({
140
+ 'hidden_size': HIDDEN_SIZE,
141
+ 'intermediate_size': INTERMEDIATE_SIZE,
142
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
143
+ })
144
+ config_json['tracker_config']['vision_config']['backbone_config'].update({
145
+ 'hidden_size': HIDDEN_SIZE,
146
+ 'intermediate_size': INTERMEDIATE_SIZE,
147
+ 'num_attention_heads': NUM_ATTENTION_HEADS,
148
+ 'global_attn_indexes': [1, 3, 5, 7],
149
+ 'num_hidden_layers': 8,
150
+ })
151
+ config_json['tracker_config']['vision_config'].update({
152
+ 'fpn_hidden_size': HIDDEN_SIZE,
153
+ })
154
+
155
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
156
+ json.dump(config_json, f, indent=2)
157
+
158
+ config = Sam3Config.from_pretrained(
159
+ save_folder,
160
+ trust_remote_code=True,
161
+ )
162
+ print(config)
163
+ torch.set_default_dtype(torch.float32)
164
+ model = Sam3Model(config)
165
+ set_seed(42)
166
+ model = model.cpu()
167
+ with torch.no_grad():
168
+ for name, p in sorted(model.named_parameters()):
169
+ torch.nn.init.normal_(p, 0, 0.1)
170
+ print(name, p.shape)
171
+ model.save_pretrained(save_folder)
172
+ ```
173
+
174
+ ### Printing the model:
175
+
176
+ ```text
177
+ Sam3Model(
178
+ (vision_encoder): Sam3VisionModel(
179
+ (backbone): Sam3ViTModel(
180
+ (embeddings): Sam3ViTEmbeddings(
181
+ (patch_embeddings): Sam3ViTPatchEmbeddings(
182
+ (projection): Conv2d(3, 16, kernel_size=(14, 14), stride=(14, 14), bias=False)
183
+ )
184
+ (dropout): Dropout(p=0.0, inplace=False)
185
+ )
186
+ (layer_norm): LayerNorm((16,), eps=1e-06, elementwise_affine=True)
187
+ (layers): ModuleList(
188
+ (0-7): 8 x Sam3ViTLayer(
189
+ (layer_norm1): LayerNorm((16,), eps=1e-06, elementwise_affine=True)
190
+ (rotary_emb): Sam3ViTRotaryEmbedding()
191
+ (attention): Sam3ViTRoPEAttention(
192
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
193
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
194
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
195
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
196
+ )
197
+ (layer_norm2): LayerNorm((16,), eps=1e-06, elementwise_affine=True)
198
+ (mlp): Sam3MLP(
199
+ (activation_fn): GELUActivation()
200
+ (fc1): Linear(in_features=16, out_features=32, bias=True)
201
+ (fc2): Linear(in_features=32, out_features=16, bias=True)
202
+ (dropout): Dropout(p=0.0, inplace=False)
203
+ )
204
+ (dropout): Dropout(p=0.0, inplace=False)
205
+ )
206
+ )
207
+ )
208
+ (neck): Sam3VisionNeck(
209
+ (position_encoding): Sam3SinePositionEmbedding()
210
+ (fpn_layers): ModuleList(
211
+ (0): Sam3FPNLayer(
212
+ (scale_layers): ModuleList(
213
+ (0): ConvTranspose2d(16, 8, kernel_size=(2, 2), stride=(2, 2))
214
+ (1): GELU(approximate='none')
215
+ (2): ConvTranspose2d(8, 4, kernel_size=(2, 2), stride=(2, 2))
216
+ )
217
+ (proj1): Conv2d(4, 16, kernel_size=(1, 1), stride=(1, 1))
218
+ (proj2): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
219
+ )
220
+ (1): Sam3FPNLayer(
221
+ (scale_layers): ModuleList(
222
+ (0): ConvTranspose2d(16, 8, kernel_size=(2, 2), stride=(2, 2))
223
+ )
224
+ (proj1): Conv2d(8, 16, kernel_size=(1, 1), stride=(1, 1))
225
+ (proj2): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
226
+ )
227
+ (2): Sam3FPNLayer(
228
+ (scale_layers): ModuleList()
229
+ (proj1): Conv2d(16, 16, kernel_size=(1, 1), stride=(1, 1))
230
+ (proj2): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
231
+ )
232
+ (3): Sam3FPNLayer(
233
+ (scale_layers): ModuleList(
234
+ (0): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
235
+ )
236
+ (proj1): Conv2d(16, 16, kernel_size=(1, 1), stride=(1, 1))
237
+ (proj2): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
238
+ )
239
+ )
240
+ )
241
+ )
242
+ (text_encoder): CLIPTextModelWithProjection(
243
+ (text_model): CLIPTextTransformer(
244
+ (embeddings): CLIPTextEmbeddings(
245
+ (token_embedding): Embedding(49408, 16)
246
+ (position_embedding): Embedding(32, 16)
247
+ )
248
+ (encoder): CLIPEncoder(
249
+ (layers): ModuleList(
250
+ (0-1): 2 x CLIPEncoderLayer(
251
+ (self_attn): CLIPAttention(
252
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
253
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
254
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
255
+ (out_proj): Linear(in_features=16, out_features=16, bias=True)
256
+ )
257
+ (layer_norm1): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
258
+ (mlp): CLIPMLP(
259
+ (activation_fn): GELUActivation()
260
+ (fc1): Linear(in_features=16, out_features=32, bias=True)
261
+ (fc2): Linear(in_features=32, out_features=16, bias=True)
262
+ )
263
+ (layer_norm2): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
264
+ )
265
+ )
266
+ )
267
+ (final_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
268
+ )
269
+ (text_projection): Linear(in_features=16, out_features=16, bias=False)
270
+ )
271
+ (text_projection): Linear(in_features=16, out_features=16, bias=True)
272
+ (geometry_encoder): Sam3GeometryEncoder(
273
+ (position_encoding): Sam3SinePositionEmbedding()
274
+ (label_embed): Embedding(2, 16)
275
+ (cls_embed): Embedding(1, 16)
276
+ (boxes_direct_project): Linear(in_features=4, out_features=16, bias=True)
277
+ (boxes_pool_project): Conv2d(16, 16, kernel_size=(7, 7), stride=(1, 1))
278
+ (boxes_pos_enc_project): Linear(in_features=18, out_features=16, bias=True)
279
+ (vision_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
280
+ (final_proj): Linear(in_features=16, out_features=16, bias=True)
281
+ (prompt_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
282
+ (layers): ModuleList(
283
+ (0-2): 3 x Sam3GeometryEncoderLayer(
284
+ (layer_norm1): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
285
+ (self_attn): Sam3Attention(
286
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
287
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
288
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
289
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
290
+ )
291
+ (dropout): Dropout(p=0.1, inplace=False)
292
+ (cross_attn): Sam3Attention(
293
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
294
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
295
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
296
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
297
+ )
298
+ (layer_norm2): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
299
+ (mlp): Sam3MLP(
300
+ (activation_fn): ReLU()
301
+ (fc1): Linear(in_features=16, out_features=32, bias=True)
302
+ (fc2): Linear(in_features=32, out_features=16, bias=True)
303
+ (dropout): Dropout(p=0.0, inplace=False)
304
+ )
305
+ (layer_norm3): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
306
+ )
307
+ )
308
+ (output_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
309
+ )
310
+ (detr_encoder): Sam3DetrEncoder(
311
+ (layers): ModuleList(
312
+ (0-5): 6 x Sam3DetrEncoderLayer(
313
+ (layer_norm1): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
314
+ (self_attn): Sam3Attention(
315
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
316
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
317
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
318
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
319
+ )
320
+ (dropout): Dropout(p=0.1, inplace=False)
321
+ (cross_attn): Sam3Attention(
322
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
323
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
324
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
325
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
326
+ )
327
+ (layer_norm2): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
328
+ (mlp): Sam3MLP(
329
+ (activation_fn): ReLU()
330
+ (fc1): Linear(in_features=16, out_features=32, bias=True)
331
+ (fc2): Linear(in_features=32, out_features=16, bias=True)
332
+ (dropout): Dropout(p=0.0, inplace=False)
333
+ )
334
+ (layer_norm3): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
335
+ )
336
+ )
337
+ )
338
+ (detr_decoder): Sam3DetrDecoder(
339
+ (layers): ModuleList(
340
+ (0-5): 6 x Sam3DetrDecoderLayer(
341
+ (self_attn): Sam3Attention(
342
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
343
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
344
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
345
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
346
+ )
347
+ (self_attn_dropout): Dropout(p=0.1, inplace=False)
348
+ (self_attn_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
349
+ (text_cross_attn): Sam3Attention(
350
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
351
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
352
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
353
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
354
+ )
355
+ (text_cross_attn_dropout): Dropout(p=0.1, inplace=False)
356
+ (text_cross_attn_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
357
+ (vision_cross_attn): Sam3Attention(
358
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
359
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
360
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
361
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
362
+ )
363
+ (vision_cross_attn_dropout): Dropout(p=0.1, inplace=False)
364
+ (vision_cross_attn_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
365
+ (mlp): Sam3MLP(
366
+ (activation_fn): ReLU()
367
+ (fc1): Linear(in_features=16, out_features=32, bias=True)
368
+ (fc2): Linear(in_features=32, out_features=16, bias=True)
369
+ (dropout): Dropout(p=0.0, inplace=False)
370
+ )
371
+ (mlp_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
372
+ (mlp_dropout): Dropout(p=0.1, inplace=False)
373
+ )
374
+ )
375
+ (output_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
376
+ (box_head): Sam3DecoderMLP(
377
+ (layer1): Linear(in_features=16, out_features=16, bias=True)
378
+ (layer2): Linear(in_features=16, out_features=16, bias=True)
379
+ (layer3): Linear(in_features=16, out_features=4, bias=True)
380
+ )
381
+ (query_embed): Embedding(200, 16)
382
+ (reference_points): Embedding(200, 4)
383
+ (presence_token): Embedding(1, 16)
384
+ (presence_head): Sam3DecoderMLP(
385
+ (layer1): Linear(in_features=16, out_features=16, bias=True)
386
+ (layer2): Linear(in_features=16, out_features=16, bias=True)
387
+ (layer3): Linear(in_features=16, out_features=1, bias=True)
388
+ )
389
+ (presence_layer_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
390
+ (ref_point_head): Sam3DecoderMLP(
391
+ (layer1): Linear(in_features=32, out_features=16, bias=True)
392
+ (layer2): Linear(in_features=16, out_features=16, bias=True)
393
+ )
394
+ (box_rpb_embed_x): Sam3DecoderMLP(
395
+ (layer1): Linear(in_features=2, out_features=16, bias=True)
396
+ (layer2): Linear(in_features=16, out_features=2, bias=True)
397
+ )
398
+ (box_rpb_embed_y): Sam3DecoderMLP(
399
+ (layer1): Linear(in_features=2, out_features=16, bias=True)
400
+ (layer2): Linear(in_features=16, out_features=2, bias=True)
401
+ )
402
+ (position_encoding): Sam3SinePositionEmbedding()
403
+ )
404
+ (mask_decoder): Sam3MaskDecoder(
405
+ (pixel_decoder): Sam3PixelDecoder(
406
+ (conv_layers): ModuleList(
407
+ (0-2): 3 x Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
408
+ )
409
+ (norms): ModuleList(
410
+ (0-2): 3 x GroupNorm(8, 16, eps=1e-05, affine=True)
411
+ )
412
+ )
413
+ (mask_embedder): Sam3MaskEmbedder(
414
+ (layers): ModuleList(
415
+ (0-2): 3 x Linear(in_features=16, out_features=16, bias=True)
416
+ )
417
+ (activation): ReLU()
418
+ )
419
+ (instance_projection): Conv2d(16, 16, kernel_size=(1, 1), stride=(1, 1))
420
+ (semantic_projection): Conv2d(16, 1, kernel_size=(1, 1), stride=(1, 1))
421
+ (prompt_cross_attn): Sam3Attention(
422
+ (q_proj): Linear(in_features=16, out_features=16, bias=True)
423
+ (k_proj): Linear(in_features=16, out_features=16, bias=True)
424
+ (v_proj): Linear(in_features=16, out_features=16, bias=True)
425
+ (o_proj): Linear(in_features=16, out_features=16, bias=True)
426
+ )
427
+ (prompt_cross_attn_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
428
+ (prompt_cross_attn_dropout): Dropout(p=0.0, inplace=False)
429
+ )
430
+ (dot_product_scoring): Sam3DotProductScoring(
431
+ (text_mlp): Sam3DecoderMLP(
432
+ (layer1): Linear(in_features=16, out_features=32, bias=True)
433
+ (layer2): Linear(in_features=32, out_features=16, bias=True)
434
+ )
435
+ (text_mlp_dropout): Dropout(p=0.1, inplace=False)
436
+ (text_mlp_out_norm): LayerNorm((16,), eps=1e-05, elementwise_affine=True)
437
+ (text_proj): Linear(in_features=16, out_features=16, bias=True)
438
+ (query_proj): Linear(in_features=16, out_features=16, bias=True)
439
+ )
440
+ )
441
+ ```
config.json ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Sam3Model"
4
+ ],
5
+ "detr_decoder_config": {
6
+ "box_rpb_mode": "log",
7
+ "dropout": 0.1,
8
+ "hidden_act": "relu",
9
+ "hidden_dropout": 0.0,
10
+ "hidden_size": 16,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 32,
13
+ "layer_norm_eps": 1e-06,
14
+ "model_type": "sam3_detr_decoder",
15
+ "num_attention_heads": 2,
16
+ "num_layers": 6,
17
+ "num_queries": 200,
18
+ "use_presence_token": true
19
+ },
20
+ "detr_encoder_config": {
21
+ "dropout": 0.1,
22
+ "hidden_act": "relu",
23
+ "hidden_dropout": 0.0,
24
+ "hidden_size": 16,
25
+ "initializer_range": 0.02,
26
+ "intermediate_size": 32,
27
+ "layer_norm_eps": 1e-06,
28
+ "model_type": "sam3_detr_encoder",
29
+ "num_attention_heads": 2,
30
+ "num_layers": 6
31
+ },
32
+ "dtype": "float32",
33
+ "geometry_encoder_config": {
34
+ "dropout": 0.1,
35
+ "hidden_act": "relu",
36
+ "hidden_dropout": 0.0,
37
+ "hidden_size": 16,
38
+ "initializer_range": 0.02,
39
+ "intermediate_size": 32,
40
+ "layer_norm_eps": 1e-06,
41
+ "model_type": "sam3_geometry_encoder",
42
+ "num_attention_heads": 2,
43
+ "num_layers": 3,
44
+ "roi_size": 7
45
+ },
46
+ "initializer_range": 0.02,
47
+ "mask_decoder_config": {
48
+ "dropout": 0.0,
49
+ "hidden_size": 16,
50
+ "initializer_range": 0.02,
51
+ "intermediate_size": 32,
52
+ "layer_norm_eps": 1e-06,
53
+ "model_type": "sam3_mask_decoder",
54
+ "num_attention_heads": 2,
55
+ "num_upsampling_stages": 3
56
+ },
57
+ "model_type": "sam3",
58
+ "text_config": {
59
+ "attention_dropout": 0.0,
60
+ "hidden_act": "gelu",
61
+ "hidden_size": 16,
62
+ "initializer_factor": 1.0,
63
+ "initializer_range": 0.02,
64
+ "intermediate_size": 32,
65
+ "layer_norm_eps": 1e-05,
66
+ "max_position_embeddings": 32,
67
+ "model_type": "clip_text_model",
68
+ "num_attention_heads": 2,
69
+ "num_hidden_layers": 2,
70
+ "projection_dim": 16,
71
+ "vocab_size": 49408
72
+ },
73
+ "transformers_version": "5.0.0.dev0",
74
+ "vision_config": {
75
+ "backbone_config": {
76
+ "_name_or_path": "",
77
+ "add_cross_attention": false,
78
+ "architectures": null,
79
+ "attention_dropout": 0.0,
80
+ "bos_token_id": null,
81
+ "chunk_size_feed_forward": 0,
82
+ "cross_attention_hidden_size": null,
83
+ "decoder_start_token_id": null,
84
+ "dtype": null,
85
+ "eos_token_id": null,
86
+ "finetuning_task": null,
87
+ "fpn_hidden_size": 16,
88
+ "global_attn_indexes": [
89
+ 1,
90
+ 3,
91
+ 5,
92
+ 7
93
+ ],
94
+ "hidden_act": "gelu",
95
+ "hidden_dropout": 0.0,
96
+ "hidden_size": 16,
97
+ "id2label": {
98
+ "0": "LABEL_0",
99
+ "1": "LABEL_1"
100
+ },
101
+ "image_size": 1008,
102
+ "initializer_range": 0.02,
103
+ "intermediate_size": 32,
104
+ "is_decoder": false,
105
+ "is_encoder_decoder": false,
106
+ "label2id": {
107
+ "LABEL_0": 0,
108
+ "LABEL_1": 1
109
+ },
110
+ "layer_norm_eps": 1e-06,
111
+ "layer_scale_init_value": null,
112
+ "model_type": "sam3_vit_model",
113
+ "num_attention_heads": 2,
114
+ "num_channels": 3,
115
+ "num_hidden_layers": 8,
116
+ "output_attentions": false,
117
+ "output_hidden_states": false,
118
+ "pad_token_id": null,
119
+ "patch_size": 14,
120
+ "prefix": null,
121
+ "pretrain_image_size": 336,
122
+ "problem_type": null,
123
+ "qkv_bias": true,
124
+ "return_dict": true,
125
+ "rope_theta": 10000.0,
126
+ "sep_token_id": null,
127
+ "task_specific_params": null,
128
+ "tie_encoder_decoder": false,
129
+ "tie_word_embeddings": true,
130
+ "tokenizer_class": null,
131
+ "window_size": 24
132
+ },
133
+ "backbone_feature_sizes": [
134
+ [
135
+ 288,
136
+ 288
137
+ ],
138
+ [
139
+ 144,
140
+ 144
141
+ ],
142
+ [
143
+ 72,
144
+ 72
145
+ ]
146
+ ],
147
+ "fpn_hidden_size": 16,
148
+ "fpn_kernel_size": 2,
149
+ "fpn_stride": 2,
150
+ "hidden_act": "gelu",
151
+ "initializer_range": 0.02,
152
+ "layer_norm_eps": 1e-06,
153
+ "model_type": "sam3_vision_model",
154
+ "num_feature_levels": 3,
155
+ "scale_factors": [
156
+ 4.0,
157
+ 2.0,
158
+ 1.0,
159
+ 0.5
160
+ ]
161
+ }
162
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20016f8717edbf11d8a2cfbfc65f4c83548cefddfb7f5828332d37911c44f0bb
3
+ size 4324560
processor_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "crop_size": null,
4
+ "data_format": "channels_first",
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.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "image_processor_type": "Sam3ImageProcessorFast",
19
+ "image_seq_length": null,
20
+ "image_std": [
21
+ 0.5,
22
+ 0.5,
23
+ 0.5
24
+ ],
25
+ "input_data_format": null,
26
+ "mask_size": {
27
+ "height": 288,
28
+ "width": 288
29
+ },
30
+ "pad_size": null,
31
+ "processor_class": "Sam3Processor",
32
+ "resample": 2,
33
+ "rescale_factor": 0.00392156862745098,
34
+ "return_tensors": null,
35
+ "size": {
36
+ "height": 1008,
37
+ "width": 1008
38
+ }
39
+ },
40
+ "point_pad_value": -10,
41
+ "processor_class": "Sam3Processor",
42
+ "target_size": 1008
43
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|startoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<|endoftext|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "49406": {
5
+ "content": "<|startoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "49407": {
13
+ "content": "<|endoftext|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ }
20
+ },
21
+ "bos_token": "<|startoftext|>",
22
+ "clean_up_tokenization_spaces": false,
23
+ "do_lower_case": true,
24
+ "eos_token": "<|endoftext|>",
25
+ "errors": "replace",
26
+ "extra_special_tokens": {},
27
+ "max_length": 32,
28
+ "model_max_length": 32,
29
+ "pad_token": "<|endoftext|>",
30
+ "processor_class": "Sam3Processor",
31
+ "tokenizer_class": "CLIPTokenizer",
32
+ "unk_token": "<|endoftext|>"
33
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff