Image Classification
timm
Safetensors
Transformers
rwightman HF Staff commited on
Commit
fb9df03
·
verified ·
1 Parent(s): f0c9aa2

Add model

Browse files
Files changed (3) hide show
  1. README.md +206 -0
  2. config.json +34 -0
  3. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ - transformers
6
+ pipeline_tag: image-classification
7
+ library_name: timm
8
+ license: apache-2.0
9
+ datasets:
10
+ - imagenet-1k
11
+ ---
12
+ # Model card for vit_dwee_patch16_reg1_gap_256.sbb_in1k
13
+
14
+ A Vision Transformer (ViT) image classification model. This is a `timm` specific variation of the architecture with registers, global average pooling, differential attention.
15
+
16
+ There are a number of models in the lower end of model scales that originate in `timm`:
17
+
18
+ | variant | width | mlp width (mult) | heads | depth | timm orig |
19
+ | ------- | ----- | ---------------- | ----- | ----- | ---- |
20
+ | tiny | 192 | 768 (4) | 3 | 12 | n |
21
+ | wee | 256 | 1280 (5) | 4 | 14 | y |
22
+ | dwee | 256 | 1280 (5) | 4 | 14 (differential) | y |
23
+ | pwee | 256 | 1280 (5) | 4 | 16 (parallel) | y |
24
+ | dpwee | 256 | 1280 (5) | 4 | 16 (parallel + differential) | y |
25
+ | small | 384 | 1536 (4) | 6 | 12 | n |
26
+ | little | 320 | 1792 (5.6) | 5 | 14 | y |
27
+ | medium | 512 | 2048 (4) | 8 | 12 | y |
28
+ | mediumd | 512 | 2048 (4) | 8 | 20 | y |
29
+ | betwixt | 640 | 2560 (4) | 10 | 12 | y |
30
+ | base | 768 | 3072 (4) | 12 | 12 | n |
31
+ | so150m2 | 832 | 2176 (2.57) | 13 | 21 | y |
32
+ | so150m | 896 | 2304 (2.62) | 14 | 18 | y |
33
+
34
+ Trained on ImageNet-1k in `timm` using recipe template described below.
35
+
36
+ Recipe details:
37
+ * Searching for better baselines. Influced by Swin/DeiT/DeiT-III but w/ increased weight decay, moderate (in12k) to high (in1k) augmentation. Layer-decay used for fine-tune. Some runs used BCE and/or NAdamW instead of AdamW.
38
+ * See [train_hparams.yaml](./train_hparams.yaml) for specifics of each model.
39
+
40
+
41
+ ## Model Details
42
+ - **Model Type:** Image Classification / Feature Encoder
43
+ - **Model Stats:**
44
+ - Params (M): 13.4
45
+ - GMACs: 3.8
46
+ - Activations (M): 17.6
47
+ - Image size: 256 x 256
48
+ - **Papers:**
49
+ - Vision Transformers Need Registers: https://arxiv.org/abs/2309.16588
50
+ - Differential Transformer: https://arxiv.org/abs/2410.05258
51
+ - An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
52
+ - **Dataset:** ImageNet-1k
53
+ - **Original:** https://github.com/huggingface/pytorch-image-models
54
+
55
+ ## Model Usage
56
+ ### Image Classification
57
+ ```python
58
+ from urllib.request import urlopen
59
+ from PIL import Image
60
+ import timm
61
+
62
+ img = Image.open(urlopen(
63
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
64
+ ))
65
+
66
+ model = timm.create_model('vit_dwee_patch16_reg1_gap_256.sbb_in1k', pretrained=True)
67
+ model = model.eval()
68
+
69
+ # get model specific transforms (normalization, resize)
70
+ data_config = timm.data.resolve_model_data_config(model)
71
+ transforms = timm.data.create_transform(**data_config, is_training=False)
72
+
73
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
74
+
75
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
76
+ ```
77
+
78
+ ### Feature Map Extraction
79
+ ```python
80
+ from urllib.request import urlopen
81
+ from PIL import Image
82
+ import timm
83
+
84
+ img = Image.open(urlopen(
85
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
86
+ ))
87
+
88
+ model = timm.create_model(
89
+ 'vit_dwee_patch16_reg1_gap_256.sbb_in1k',
90
+ pretrained=True,
91
+ features_only=True,
92
+ )
93
+ model = model.eval()
94
+
95
+ # get model specific transforms (normalization, resize)
96
+ data_config = timm.data.resolve_model_data_config(model)
97
+ transforms = timm.data.create_transform(**data_config, is_training=False)
98
+
99
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
100
+
101
+ for o in output:
102
+ # print shape of each feature map in output
103
+ # e.g.:
104
+ # torch.Size([1, 256, 16, 16])
105
+ # torch.Size([1, 256, 16, 16])
106
+ # torch.Size([1, 256, 16, 16])
107
+
108
+ print(o.shape)
109
+ ```
110
+
111
+ ### Image Embeddings
112
+ ```python
113
+ from urllib.request import urlopen
114
+ from PIL import Image
115
+ import timm
116
+
117
+ img = Image.open(urlopen(
118
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
119
+ ))
120
+
121
+ model = timm.create_model(
122
+ 'vit_dwee_patch16_reg1_gap_256.sbb_in1k',
123
+ pretrained=True,
124
+ num_classes=0, # remove classifier nn.Linear
125
+ )
126
+ model = model.eval()
127
+
128
+ # get model specific transforms (normalization, resize)
129
+ data_config = timm.data.resolve_model_data_config(model)
130
+ transforms = timm.data.create_transform(**data_config, is_training=False)
131
+
132
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
133
+
134
+ # or equivalently (without needing to set num_classes=0)
135
+
136
+ output = model.forward_features(transforms(img).unsqueeze(0))
137
+ # output is unpooled, a (1, 257, 256) shaped tensor
138
+
139
+ output = model.forward_head(output, pre_logits=True)
140
+ # output is a (1, num_features) shaped tensor
141
+ ```
142
+
143
+ ## Model Comparison
144
+ | model | top1 | top5 | param_count | img_size |
145
+ | -------------------------------------------------- | ------ | ------ | ----------- | -------- |
146
+ | [vit_so150m2_patch16_reg1_gap_448.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_so150m2_patch16_reg1_gap_448.sbb2_e200_in12k_ft_in1k) | 88.068 | 98.588 | 136.33 | 448 |
147
+ | [vit_so150m2_patch16_reg1_gap_384.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_so150m2_patch16_reg1_gap_384.sbb2_e200_in12k_ft_in1k) | 87.930 | 98.502 | 136.33 | 384 |
148
+ | [vit_so150m2_patch16_reg1_gap_256.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_so150m2_patch16_reg1_gap_256.sbb2_e200_in12k_ft_in1k) | 87.308 | 98.326 | 136.33 | 256 |
149
+ | [vit_mediumd_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k) | 87.438 | 98.256 | 64.11 | 384 |
150
+ | [vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k) | 86.608 | 97.934 | 64.11 | 256 |
151
+ | [vit_betwixt_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k) | 86.594 | 98.02 | 60.4 | 384 |
152
+ | [vit_mediumd_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 86.202 | 97.874 | 64.11 | 256 |
153
+ | [vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k) | 85.734 | 97.61 | 60.4 | 256 |
154
+ | [vit_betwixt_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 85.418 | 97.480 | 60.4 | 256 |
155
+ | [vit_medium_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_medium_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 84.930 | 97.386 | 38.88 | 256 |
156
+ | [vit_mediumd_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_mediumd_patch16_rope_reg1_gap_256.sbb_in1k) | 84.322 | 96.812 | 63.95 | 256 |
157
+ | [vit_betwixt_patch16_rope_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_rope_reg4_gap_256.sbb_in1k) | 83.906 | 96.684 | 60.23 | 256 |
158
+ | [vit_base_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_base_patch16_rope_reg1_gap_256.sbb_in1k) | 83.866 | 96.67 | 86.43 | 256 |
159
+ | [vit_medium_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_rope_reg1_gap_256.sbb_in1k) | 83.81 | 96.824 | 38.74 | 256 |
160
+ | [vit_little_patch16_reg1_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_little_patch16_reg1_gap_256.sbb_in12k_ft_in1k) | 83.774 | 96.972 | 22.52 | 256 |
161
+ | [vit_betwixt_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb_in1k) | 83.706 | 96.616 | 60.4 | 256 |
162
+ | [vit_betwixt_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg1_gap_256.sbb_in1k) | 83.628 | 96.544 | 60.4 | 256 |
163
+ | [vit_medium_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_reg4_gap_256.sbb_in1k) | 83.47 | 96.622 | 38.88 | 256 |
164
+ | [vit_medium_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_reg1_gap_256.sbb_in1k) | 83.462 | 96.548 | 38.88 | 256 |
165
+ | [vit_little_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_little_patch16_reg4_gap_256.sbb_in1k) | 82.514 | 96.262 | 22.52 | 256 |
166
+ | [vit_dwee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_dwee_patch16_reg1_gap_256.sbb_in1k) | 80.998 | 95.662 | 13.43 | 256 |
167
+ | [vit_dpwee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_dpwee_patch16_reg1_gap_256.sbb_in1k) | 80.880 | 95.630 | 15.25 | 256 |
168
+ | [vit_wee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_wee_patch16_reg1_gap_256.sbb_in1k) | 80.258 | 95.360 | 13.42 | 256 |
169
+ | [vit_pwee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_pwee_patch16_reg1_gap_256.sbb_in1k) | 80.072 | 95.136 | 15.25 | 256 |
170
+
171
+ ## Citation
172
+ ```bibtex
173
+ @misc{rw2019timm,
174
+ author = {Ross Wightman},
175
+ title = {PyTorch Image Models},
176
+ year = {2019},
177
+ publisher = {GitHub},
178
+ journal = {GitHub repository},
179
+ doi = {10.5281/zenodo.4414861},
180
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
181
+ }
182
+ ```
183
+ ```bibtex
184
+ @article{darcet2023vision,
185
+ title={Vision Transformers Need Registers},
186
+ author={Darcet, Timoth{'e}e and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
187
+ journal={arXiv preprint arXiv:2309.16588},
188
+ year={2023}
189
+ }
190
+ ```
191
+ ```bibtex
192
+ @article{ye2024differential,
193
+ title={Differential transformer},
194
+ author={Ye, Tianzhu and Dong, Li and Xia, Yuqing and Sun, Yutao and Zhu, Yi and Huang, Gao and Wei, Furu},
195
+ journal={arXiv preprint arXiv:2410.05258},
196
+ year={2024}
197
+ }
198
+ ```
199
+ ```bibtex
200
+ @article{dosovitskiy2020vit,
201
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
202
+ author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
203
+ journal={ICLR},
204
+ year={2021}
205
+ }
206
+ ```
config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "vit_dwee_patch16_reg1_gap_256",
3
+ "num_classes": 1000,
4
+ "num_features": 256,
5
+ "global_pool": "avg",
6
+ "pretrained_cfg": {
7
+ "tag": "sbb_in1k",
8
+ "custom_load": false,
9
+ "input_size": [
10
+ 3,
11
+ 256,
12
+ 256
13
+ ],
14
+ "fixed_input_size": true,
15
+ "interpolation": "bicubic",
16
+ "crop_pct": 0.95,
17
+ "crop_mode": "center",
18
+ "mean": [
19
+ 0.5,
20
+ 0.5,
21
+ 0.5
22
+ ],
23
+ "std": [
24
+ 0.5,
25
+ 0.5,
26
+ 0.5
27
+ ],
28
+ "num_classes": 1000,
29
+ "pool_size": null,
30
+ "first_conv": "patch_embed.proj",
31
+ "classifier": "head",
32
+ "license": "apache-2.0"
33
+ }
34
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b864751f405887dd833d69b3a42f78853db911a2d38bb614bdbb5014f34a4901
3
+ size 53725784