timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers
rwightman HF staff commited on
Commit
b1aa35b
·
verified ·
1 Parent(s): 303fe27
Files changed (4) hide show
  1. README.md +192 -0
  2. config.json +33 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-12k
10
+ ---
11
+ # Model card for vit_so150m2_patch16_reg1_gap_384.sbb_e200_in12k_ft_in1k
12
+
13
+ A Vision Transformer (ViT) image classification model. This is a `timm` specific variation of the architecture with registers, global average pooling.
14
+
15
+ There are a number of models in the lower end of model scales that originate in `timm`:
16
+
17
+ | variant | width | mlp width (mult) | heads | depth | timm orig |
18
+ | ------- | ----- | ---------------- | ----- | ----- | ---- |
19
+ | tiny | 192 | 768 (4) | 3 | 12 | n |
20
+ | wee | 256 | 1280 (5) | 4 | 14 | y |
21
+ | pwee | 256 | 1280 (5) | 4 | 16 (parallel) | y |
22
+ | small | 384 | 1536 (4) | 6 | 12 | n |
23
+ | little | 320 | 1792 (5.6) | 5 | 14 | y |
24
+ | medium | 512 | 2048 (4) | 8 | 12 | y |
25
+ | mediumd | 512 | 2048 (4) | 8 | 20 | y |
26
+ | betwixt | 640 | 2560 (4) | 10 | 12 | y |
27
+ | base | 768 | 3072 (4) | 12 | 12 | n |
28
+ | so150m2 | 832 | 2176 (2.57) | 13 | 21 | n |
29
+ | so150 | 896 | 2304 (2.62) | 14 | 18 | n |
30
+
31
+ Pretrained on ImageNet-12k and fine-tuned on ImageNet-1k by Ross Wightman in `timm` using recipe template described below.
32
+
33
+ Recipe details:
34
+ * 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.
35
+ * See [train_hparams.yaml](./train_hparams.yaml) for specifics of each model.
36
+
37
+
38
+ ## Model Details
39
+ - **Model Type:** Image classification / feature backbone
40
+ - **Model Stats:**
41
+ - Params (M): 136.3
42
+ - GMACs: 89.5
43
+ - Activations (M): 178.2
44
+ - Image size: 384 x 384
45
+ - **Papers:**
46
+ - Vision Transformers Need Registers: https://arxiv.org/abs/2309.16588
47
+ - An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
48
+ - **Dataset:** ImageNet-1k
49
+ - **Pretrain Dataset:** ImageNet-12k
50
+ - **Original:** https://github.com/huggingface/pytorch-image-models
51
+
52
+ ## Model Usage
53
+ ### Image Classification
54
+ ```python
55
+ from urllib.request import urlopen
56
+ from PIL import Image
57
+ import timm
58
+
59
+ img = Image.open(urlopen(
60
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
61
+ ))
62
+
63
+ model = timm.create_model('vit_so150m2_patch16_reg1_gap_384.sbb_e200_in12k_ft_in1k', pretrained=True)
64
+ model = model.eval()
65
+
66
+ # get model specific transforms (normalization, resize)
67
+ data_config = timm.data.resolve_model_data_config(model)
68
+ transforms = timm.data.create_transform(**data_config, is_training=False)
69
+
70
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
71
+
72
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
73
+ ```
74
+
75
+ ### Feature Map Extraction
76
+ ```python
77
+ from urllib.request import urlopen
78
+ from PIL import Image
79
+ import timm
80
+
81
+ img = Image.open(urlopen(
82
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
83
+ ))
84
+
85
+ model = timm.create_model(
86
+ 'vit_so150m2_patch16_reg1_gap_384.sbb_e200_in12k_ft_in1k',
87
+ pretrained=True,
88
+ features_only=True,
89
+ )
90
+ model = model.eval()
91
+
92
+ # get model specific transforms (normalization, resize)
93
+ data_config = timm.data.resolve_model_data_config(model)
94
+ transforms = timm.data.create_transform(**data_config, is_training=False)
95
+
96
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
97
+
98
+ for o in output:
99
+ # print shape of each feature map in output
100
+ # e.g.:
101
+ # torch.Size([1, 832, 24, 24])
102
+ # torch.Size([1, 832, 24, 24])
103
+ # torch.Size([1, 832, 24, 24])
104
+
105
+ print(o.shape)
106
+ ```
107
+
108
+ ### Image Embeddings
109
+ ```python
110
+ from urllib.request import urlopen
111
+ from PIL import Image
112
+ import timm
113
+
114
+ img = Image.open(urlopen(
115
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
116
+ ))
117
+
118
+ model = timm.create_model(
119
+ 'vit_so150m2_patch16_reg1_gap_384.sbb_e200_in12k_ft_in1k',
120
+ pretrained=True,
121
+ num_classes=0, # remove classifier nn.Linear
122
+ )
123
+ model = model.eval()
124
+
125
+ # get model specific transforms (normalization, resize)
126
+ data_config = timm.data.resolve_model_data_config(model)
127
+ transforms = timm.data.create_transform(**data_config, is_training=False)
128
+
129
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
130
+
131
+ # or equivalently (without needing to set num_classes=0)
132
+
133
+ output = model.forward_features(transforms(img).unsqueeze(0))
134
+ # output is unpooled, a (1, 577, 832) shaped tensor
135
+
136
+ output = model.forward_head(output, pre_logits=True)
137
+ # output is a (1, num_features) shaped tensor
138
+ ```
139
+
140
+ ## Model Comparison
141
+ | model | top1 | top5 | param_count | img_size |
142
+ | -------------------------------------------------- | ------ | ------ | ----------- | -------- |
143
+ | [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 |
144
+ | [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 |
145
+ | [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 |
146
+ | [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 |
147
+ | [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 |
148
+ | [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 |
149
+ | [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 |
150
+ | [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 |
151
+ | [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 |
152
+ | [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 |
153
+ | [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 |
154
+ | [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 |
155
+ | [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 |
156
+ | [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 |
157
+ | [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 |
158
+ | [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 |
159
+ | [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 |
160
+ | [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 |
161
+ | [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 |
162
+ | [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 |
163
+ | [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 |
164
+
165
+ ## Citation
166
+ ```bibtex
167
+ @misc{rw2019timm,
168
+ author = {Ross Wightman},
169
+ title = {PyTorch Image Models},
170
+ year = {2019},
171
+ publisher = {GitHub},
172
+ journal = {GitHub repository},
173
+ doi = {10.5281/zenodo.4414861},
174
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
175
+ }
176
+ ```
177
+ ```bibtex
178
+ @article{darcet2023vision,
179
+ title={Vision Transformers Need Registers},
180
+ author={Darcet, Timoth{'e}e and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
181
+ journal={arXiv preprint arXiv:2309.16588},
182
+ year={2023}
183
+ }
184
+ ```
185
+ ```bibtex
186
+ @article{dosovitskiy2020vit,
187
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
188
+ 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},
189
+ journal={ICLR},
190
+ year={2021}
191
+ }
192
+ ```
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "vit_so150m2_patch16_reg1_gap_384",
3
+ "num_classes": 1000,
4
+ "num_features": 832,
5
+ "global_pool": "avg",
6
+ "pretrained_cfg": {
7
+ "tag": "sbb_e200_in12k_ft_in1k",
8
+ "custom_load": false,
9
+ "input_size": [
10
+ 3,
11
+ 384,
12
+ 384
13
+ ],
14
+ "fixed_input_size": true,
15
+ "interpolation": "bicubic",
16
+ "crop_pct": 1.0,
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
+ }
33
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1ff1146a0992b698093a873ab4327e1d44505de3e51ccddf1f7a8ed30d3f45d
3
+ size 545329264
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0799836ef0dd516d052a71fc8a43e53f6e0f43079a5729aa48924e935258e3f0
3
+ size 545407150