timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
9346c65
1 Parent(s): e796d1e
Files changed (4) hide show
  1. README.md +226 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for resnetv2_18.ra4_e3600_r224_in1k
11
+
12
+ A ResNet image classification model. Trained on ImageNet-1k by Ross Wightman.
13
+
14
+ Trained with `timm` scripts using hyper-parameters inspired by the MobileNet-V4 small, mixed with go-to hparams from `timm` and "ResNet Strikes Back".
15
+
16
+ A collection of hparam (timm .yaml config files) for this training series can be found here: https://gist.github.com/rwightman/f6705cb65c03daeebca8aa129b1b94ad
17
+
18
+ ## Model Details
19
+ - **Model Type:** Image classification / feature backbone
20
+ - **Model Stats:**
21
+ - Params (M): 11.7
22
+ - GMACs: 1.8
23
+ - Activations (M): 2.5
24
+ - Image size: train = 224 x 224, test = 288 x 288
25
+ - **Dataset:** ImageNet-1k
26
+ - **Papers:**
27
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
28
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
29
+ - Deep Residual Learning for Image Recognition: https://arxiv.org/abs/1512.03385
30
+ - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
31
+
32
+ ## Model Usage
33
+ ### Image Classification
34
+ ```python
35
+ from urllib.request import urlopen
36
+ from PIL import Image
37
+ import timm
38
+
39
+ img = Image.open(urlopen(
40
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
41
+ ))
42
+
43
+ model = timm.create_model('resnetv2_18.ra4_e3600_r224_in1k', pretrained=True)
44
+ model = model.eval()
45
+
46
+ # get model specific transforms (normalization, resize)
47
+ data_config = timm.data.resolve_model_data_config(model)
48
+ transforms = timm.data.create_transform(**data_config, is_training=False)
49
+
50
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
51
+
52
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
53
+ ```
54
+
55
+ ### Feature Map Extraction
56
+ ```python
57
+ from urllib.request import urlopen
58
+ from PIL import Image
59
+ import timm
60
+
61
+ img = Image.open(urlopen(
62
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
63
+ ))
64
+
65
+ model = timm.create_model(
66
+ 'resnetv2_18.ra4_e3600_r224_in1k',
67
+ pretrained=True,
68
+ features_only=True,
69
+ )
70
+ model = model.eval()
71
+
72
+ # get model specific transforms (normalization, resize)
73
+ data_config = timm.data.resolve_model_data_config(model)
74
+ transforms = timm.data.create_transform(**data_config, is_training=False)
75
+
76
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
77
+
78
+ for o in output:
79
+ # print shape of each feature map in output
80
+ # e.g.:
81
+ # torch.Size([1, 64, 112, 112])
82
+ # torch.Size([1, 64, 56, 56])
83
+ # torch.Size([1, 128, 28, 28])
84
+ # torch.Size([1, 256, 14, 14])
85
+ # torch.Size([1, 512, 7, 7])
86
+
87
+ print(o.shape)
88
+ ```
89
+
90
+ ### Image Embeddings
91
+ ```python
92
+ from urllib.request import urlopen
93
+ from PIL import Image
94
+ import timm
95
+
96
+ img = Image.open(urlopen(
97
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
98
+ ))
99
+
100
+ model = timm.create_model(
101
+ 'resnetv2_18.ra4_e3600_r224_in1k',
102
+ pretrained=True,
103
+ num_classes=0, # remove classifier nn.Linear
104
+ )
105
+ model = model.eval()
106
+
107
+ # get model specific transforms (normalization, resize)
108
+ data_config = timm.data.resolve_model_data_config(model)
109
+ transforms = timm.data.create_transform(**data_config, is_training=False)
110
+
111
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
112
+
113
+ # or equivalently (without needing to set num_classes=0)
114
+
115
+ output = model.forward_features(transforms(img).unsqueeze(0))
116
+ # output is unpooled, a (1, 512, 7, 7) shaped tensor
117
+
118
+ output = model.forward_head(output, pre_logits=True)
119
+ # output is a (1, num_features) shaped tensor
120
+ ```
121
+
122
+ ## Model Comparison
123
+ ### By Top-1
124
+
125
+ | model | top1 | top5 | param_count | img_size |
126
+ |--------------------------------------------------------------------------------------------------------------------------|--------|--------|-------------|----------|
127
+ | [mobilenetv4_conv_aa_large.e230_r448_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e230_r448_in12k_ft_in1k) | 84.99 | 97.294 | 32.59 | 544 |
128
+ | [mobilenetv4_conv_aa_large.e230_r384_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e230_r384_in12k_ft_in1k) | 84.772 | 97.344 | 32.59 | 480 |
129
+ | [mobilenetv4_conv_aa_large.e230_r448_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e230_r448_in12k_ft_in1k) | 84.64 | 97.114 | 32.59 | 448 |
130
+ | [mobilenetv4_hybrid_large.ix_e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.ix_e600_r384_in1k) | 84.356 | 96.892 | 37.76 | 448 |
131
+ | [mobilenetv4_conv_aa_large.e230_r384_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e230_r384_in12k_ft_in1k) | 84.314 | 97.102 | 32.59 | 384 |
132
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) | 84.266 | 96.936 | 37.76 | 448 |
133
+ | [mobilenetv4_hybrid_large.ix_e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.ix_e600_r384_in1k) | 83.990 | 96.702 | 37.76 | 384 |
134
+ | [mobilenetv4_conv_aa_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e600_r384_in1k) | 83.824 | 96.734 | 32.59 | 480 |
135
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) | 83.800 | 96.770 | 37.76 | 384 |
136
+ | [mobilenetv4_hybrid_medium.ix_e550_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k) | 83.394 | 96.760 | 11.07 | 448 |
137
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) | 83.392 | 96.622 | 32.59 | 448 |
138
+ | [mobilenetv4_conv_aa_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e600_r384_in1k) | 83.244 | 96.392 | 32.59 | 384 |
139
+ | [mobilenetv4_hybrid_medium.e200_r256_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e200_r256_in12k_ft_in1k) | 82.99 | 96.67 | 11.07 | 320 |
140
+ | [mobilenetv4_hybrid_medium.ix_e550_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k) | 82.968 | 96.474 | 11.07 | 384 |
141
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) | 82.952 | 96.266 | 32.59 | 384 |
142
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) | 82.674 | 96.31 | 32.59 | 320 |
143
+ | [mobilenetv4_hybrid_medium.ix_e550_r256_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r256_in1k) | 82.492 | 96.278 | 11.07 | 320 |
144
+ | [mobilenetv4_hybrid_medium.e200_r256_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e200_r256_in12k_ft_in1k) | 82.364 | 96.256 | 11.07 | 256 |
145
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) | 81.862 | 95.69 | 32.59 | 256 |
146
+ | [resnet50d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet50d.ra4_e3600_r224_in1k) | 81.838 | 95.922 | 25.58 | 288 |
147
+ | [mobilenetv3_large_150d.ra4_e3600_r256_in1k](http://hf.co/timm/mobilenetv3_large_150d.ra4_e3600_r256_in1k) | 81.806 | 95.9 | 14.62 | 320 |
148
+ | [mobilenetv4_hybrid_medium.ix_e550_r256_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r256_in1k) | 81.446 | 95.704 | 11.07 | 256 |
149
+ | [efficientnet_b1.ra4_e3600_r240_in1k](http://hf.co/timm/efficientnet_b1.ra4_e3600_r240_in1k) | 81.440 | 95.700 | 7.79 | 288 |
150
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) | 81.276 | 95.742 | 11.07 | 256 |
151
+ | [resnet50d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet50d.ra4_e3600_r224_in1k) | 80.952 | 95.384 | 25.58 | 224 |
152
+ | [mobilenetv3_large_150d.ra4_e3600_r256_in1k](http://hf.co/timm/mobilenetv3_large_150d.ra4_e3600_r256_in1k) | 80.944 | 95.448 | 14.62 | 256 |
153
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) | 80.858 | 95.768 | 9.72 | 320 |
154
+ | [mobilenet_edgetpu_v2_m.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenet_edgetpu_v2_m.ra4_e3600_r224_in1k) | 80.680 | 95.442 | 8.46 | 256 |
155
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) | 80.442 | 95.38 | 11.07 | 224 |
156
+ | [efficientnet_b1.ra4_e3600_r240_in1k](http://hf.co/timm/efficientnet_b1.ra4_e3600_r240_in1k) | 80.406 | 95.152 | 7.79 | 240 |
157
+ | [mobilenetv4_conv_blur_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_blur_medium.e500_r224_in1k) | 80.142 | 95.298 | 9.72 | 256 |
158
+ | [mobilenet_edgetpu_v2_m.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenet_edgetpu_v2_m.ra4_e3600_r224_in1k) | 80.130 | 95.002 | 8.46 | 224 |
159
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) | 79.928 | 95.184 | 9.72 | 256 |
160
+ | [mobilenetv4_conv_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r224_in1k) | 79.808 | 95.186 | 9.72 | 256 |
161
+ | [resnetv2_34d.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_34d.ra4_e3600_r224_in1k) | 79.590 | 94.770 | 21.82 | 288 |
162
+ | [mobilenetv4_conv_blur_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_blur_medium.e500_r224_in1k) | 79.438 | 94.932 | 9.72 | 224 |
163
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) | 79.364 | 94.754 | 5.29 | 256 |
164
+ | [mobilenetv4_conv_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r224_in1k) | 79.094 | 94.77 | 9.72 | 224 |
165
+ | [resnetv2_34.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_34.ra4_e3600_r224_in1k) | 79.072 | 94.566 | 21.80 | 288 |
166
+ | [resnet34.ra4_e3600_r224_in1k](http://hf.co/timm/resnet34.ra4_e3600_r224_in1k) | 78.952 | 94.450 | 21.80 | 288 |
167
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) | 78.584 | 94.338 | 5.29 | 224 |
168
+ | [resnetv2_34d.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_34d.ra4_e3600_r224_in1k) | 78.268 | 93.952 | 21.82 | 224 |
169
+ | [resnetv2_34.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_34.ra4_e3600_r224_in1k) | 77.636 | 93.528 | 21.80 | 224 |
170
+ | [mobilenetv1_125.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_125.ra4_e3600_r224_in1k) | 77.600 | 93.804 | 6.27 | 256 |
171
+ | [resnet34.ra4_e3600_r224_in1k](http://hf.co/timm/resnet34.ra4_e3600_r224_in1k) | 77.448 | 93.502 | 21.80 | 224 |
172
+ | [mobilenetv3_large_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv3_large_100.ra4_e3600_r224_in1k) | 77.164 | 93.336 | 5.48 | 256 |
173
+ | [mobilenetv1_125.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_125.ra4_e3600_r224_in1k) | 76.924 | 93.234 | 6.27 | 224 |
174
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) | 76.596 | 93.272 | 5.28 | 256 |
175
+ | [mobilenetv3_large_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv3_large_100.ra4_e3600_r224_in1k) | 76.310 | 92.846 | 5.48 | 224 |
176
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) | 76.094 | 93.004 | 4.23 | 256 |
177
+ | [resnetv2_18d.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_18d.ra4_e3600_r224_in1k) | 76.044 | 93.020 | 11.71 | 288 |
178
+ | [resnet18d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet18d.ra4_e3600_r224_in1k) | 76.024 | 92.780 | 11.71 | 288 |
179
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) | 75.662 | 92.504 | 5.28 | 224 |
180
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) | 75.382 | 92.312 | 4.23 | 224 |
181
+ | [resnetv2_18.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_18.ra4_e3600_r224_in1k) | 75.340 | 92.678 | 11.69 | 288 |
182
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) | 74.616 | 92.072 | 3.77 | 256 |
183
+ | [resnetv2_18d.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_18d.ra4_e3600_r224_in1k) | 74.412 | 91.936 | 11.71 | 224 |
184
+ | [resnet18d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet18d.ra4_e3600_r224_in1k) | 74.322 | 91.832 | 11.71 | 224 |
185
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) | 74.292 | 92.116 | 3.77 | 256 |
186
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) | 73.756 | 91.422 | 3.77 | 224 |
187
+ | [resnetv2_18.ra4_e3600_r224_in1k](http://hf.co/timm/resnetv2_18.ra4_e3600_r224_in1k) | 73.578 | 91.352 | 11.69 | 224 |
188
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) | 73.454 | 91.34 | 3.77 | 224 |
189
+ | [mobilenetv4_conv_small_050.e3000_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small_050.e3000_r224_in1k) | 65.810 | 86.424 | 2.24 | 256 |
190
+ | [mobilenetv4_conv_small_050.e3000_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small_050.e3000_r224_in1k) | 64.762 | 85.514 | 2.24 | 224 |
191
+
192
+ ## Citation
193
+ ```bibtex
194
+ @misc{rw2019timm,
195
+ author = {Ross Wightman},
196
+ title = {PyTorch Image Models},
197
+ year = {2019},
198
+ publisher = {GitHub},
199
+ journal = {GitHub repository},
200
+ doi = {10.5281/zenodo.4414861},
201
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
202
+ }
203
+ ```
204
+ ```bibtex
205
+ @inproceedings{wightman2021resnet,
206
+ title={ResNet strikes back: An improved training procedure in timm},
207
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
208
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
209
+ }
210
+ ```
211
+ ```bibtex
212
+ @article{He2015,
213
+ author = {Kaiming He and Xiangyu Zhang and Shaoqing Ren and Jian Sun},
214
+ title = {Deep Residual Learning for Image Recognition},
215
+ journal = {arXiv preprint arXiv:1512.03385},
216
+ year = {2015}
217
+ }
218
+ ```
219
+ ```bibtex
220
+ @article{qin2024mobilenetv4,
221
+ title={MobileNetV4-Universal Models for the Mobile Ecosystem},
222
+ author={Qin, Danfeng and Leichner, Chas and Delakis, Manolis and Fornoni, Marco and Luo, Shixin and Yang, Fan and Wang, Weijun and Banbury, Colby and Ye, Chengxi and Akin, Berkin and others},
223
+ journal={arXiv preprint arXiv:2404.10518},
224
+ year={2024}
225
+ }
226
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "resnetv2_18",
3
+ "num_classes": 1000,
4
+ "num_features": 512,
5
+ "pretrained_cfg": {
6
+ "tag": "ra4_e3600_r224_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 224,
11
+ 224
12
+ ],
13
+ "test_input_size": [
14
+ 3,
15
+ 288,
16
+ 288
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.9,
21
+ "test_crop_pct": 1.0,
22
+ "crop_mode": "center",
23
+ "mean": [
24
+ 0.5,
25
+ 0.5,
26
+ 0.5
27
+ ],
28
+ "std": [
29
+ 0.5,
30
+ 0.5,
31
+ 0.5
32
+ ],
33
+ "num_classes": 1000,
34
+ "pool_size": [
35
+ 7,
36
+ 7
37
+ ],
38
+ "first_conv": "stem.conv",
39
+ "classifier": "head.fc"
40
+ }
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cbd1843d961f937eed89815af452c0dcc63f0bb5c54b60a4cd8ed5fc66ffb3e
3
+ size 46792768
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:687c6ac8d34ef0c6d690058df7710d814fe10eb9bfbe93acf5a779d6754fb42d
3
+ size 46820726