timm
/

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