timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
12d526a
1 Parent(s): 026c834
Files changed (4) hide show
  1. README.md +213 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k
12
+
13
+ A MobileNet-V4 image classification model. Pretrained on ImageNet-12k and fine-tuned on ImageNet-1k by Ross Wightman.
14
+
15
+ A collection of hparams (timm .yaml config files) for this training series can be found here: https://gist.github.com/rwightman/f6705cb65c03daeebca8aa129b1b94ad
16
+
17
+ ## Model Details
18
+ - **Model Type:** Image classification / feature backbone
19
+ - **Model Stats:**
20
+ - Params (M): 9.7
21
+ - GMACs: 2.5
22
+ - Activations (M): 17.1
23
+ - Image size: 384 x 384
24
+ - **Dataset:** ImageNet-1k
25
+ - **Pretrain Dataset:** ImageNet-12k
26
+ - **Papers:**
27
+ - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
28
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
29
+
30
+ ## Model Usage
31
+ ### Image Classification
32
+ ```python
33
+ from urllib.request import urlopen
34
+ from PIL import Image
35
+ import timm
36
+
37
+ img = Image.open(urlopen(
38
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
39
+ ))
40
+
41
+ model = timm.create_model('mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k', pretrained=True)
42
+ model = model.eval()
43
+
44
+ # get model specific transforms (normalization, resize)
45
+ data_config = timm.data.resolve_model_data_config(model)
46
+ transforms = timm.data.create_transform(**data_config, is_training=False)
47
+
48
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
49
+
50
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
51
+ ```
52
+
53
+ ### Feature Map Extraction
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(
64
+ 'mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k',
65
+ pretrained=True,
66
+ features_only=True,
67
+ )
68
+ model = model.eval()
69
+
70
+ # get model specific transforms (normalization, resize)
71
+ data_config = timm.data.resolve_model_data_config(model)
72
+ transforms = timm.data.create_transform(**data_config, is_training=False)
73
+
74
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
75
+
76
+ for o in output:
77
+ # print shape of each feature map in output
78
+ # e.g.:
79
+ # torch.Size([1, 32, 192, 192])
80
+ # torch.Size([1, 48, 96, 96])
81
+ # torch.Size([1, 80, 48, 48])
82
+ # torch.Size([1, 160, 24, 24])
83
+ # torch.Size([1, 960, 12, 12])
84
+
85
+ print(o.shape)
86
+ ```
87
+
88
+ ### Image Embeddings
89
+ ```python
90
+ from urllib.request import urlopen
91
+ from PIL import Image
92
+ import timm
93
+
94
+ img = Image.open(urlopen(
95
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
96
+ ))
97
+
98
+ model = timm.create_model(
99
+ 'mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k',
100
+ pretrained=True,
101
+ num_classes=0, # remove classifier nn.Linear
102
+ )
103
+ model = model.eval()
104
+
105
+ # get model specific transforms (normalization, resize)
106
+ data_config = timm.data.resolve_model_data_config(model)
107
+ transforms = timm.data.create_transform(**data_config, is_training=False)
108
+
109
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
110
+
111
+ # or equivalently (without needing to set num_classes=0)
112
+
113
+ output = model.forward_features(transforms(img).unsqueeze(0))
114
+ # output is unpooled, a (1, 960, 12, 12) shaped tensor
115
+
116
+ output = model.forward_head(output, pre_logits=True)
117
+ # output is a (1, num_features) shaped tensor
118
+ ```
119
+
120
+ ## Model Comparison
121
+ ### By Top-1
122
+
123
+ | model | top1 | top5 | param_count | img_size |
124
+ |--------------------------------------------------------------------------------------------------------------------------|--------|--------|-------------|----------|
125
+ | [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 |
126
+ | [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 |
127
+ | [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 |
128
+ | [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 |
129
+ | [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 |
130
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) | 84.266 | 96.936 | 37.76 | 448 |
131
+ | [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 |
132
+ | [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 |
133
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) | 83.800 | 96.770 | 37.76 | 384 |
134
+ | [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 |
135
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) | 83.392 | 96.622 | 32.59 | 448 |
136
+ | [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 |
137
+ | [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 |
138
+ | [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 |
139
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) | 82.952 | 96.266 | 32.59 | 384 |
140
+ | [mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e250_r384_in12k_ft_in1k) | 82.738 | 96.458 | 9.72 | 384 |
141
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) | 82.674 | 96.31 | 32.59 | 320 |
142
+ | [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 |
143
+ | [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 |
144
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) | 81.862 | 95.69 | 32.59 | 256 |
145
+ | [resnet50d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet50d.ra4_e3600_r224_in1k) | 81.838 | 95.922 | 25.58 | 288 |
146
+ | [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 |
147
+ | [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 |
148
+ | [efficientnet_b1.ra4_e3600_r240_in1k](http://hf.co/timm/efficientnet_b1.ra4_e3600_r240_in1k) | 81.440 | 95.700 | 7.79 | 288 |
149
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) | 81.276 | 95.742 | 11.07 | 256 |
150
+ | [resnet50d.ra4_e3600_r224_in1k](http://hf.co/timm/resnet50d.ra4_e3600_r224_in1k) | 80.952 | 95.384 | 25.58 | 224 |
151
+ | [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 |
152
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) | 80.858 | 95.768 | 9.72 | 320 |
153
+ | [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 |
154
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) | 80.442 | 95.38 | 11.07 | 224 |
155
+ | [efficientnet_b1.ra4_e3600_r240_in1k](http://hf.co/timm/efficientnet_b1.ra4_e3600_r240_in1k) | 80.406 | 95.152 | 7.79 | 240 |
156
+ | [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 |
157
+ | [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 |
158
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) | 79.928 | 95.184 | 9.72 | 256 |
159
+ | [resnetv2_34d.ra4_e3600_r384_in1k](http://hf.co/timm/resnetv2_34d.ra4_e3600_r384_in1k) | 80.424 | 95.278 | 21.82 | 384 |
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
+ | [cs3darknet_focus_s.ra4_e3600_r256_in1k](http://hf.co/timm/cs3darknet_focus_s.ra4_e3600_r256_in1k) | 73.154 | 91.472 | 3.27 | 320 |
190
+ | [cs3darknet_focus_s.ra4_e3600_r256_in1k](http://hf.co/timm/cs3darknet_focus_s.ra4_e3600_r256_in1k) | 72.160 | 90.840 | 3.27 | 256 |
191
+ | [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 |
192
+ | [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 |
193
+
194
+ ## Citation
195
+ ```bibtex
196
+ @article{qin2024mobilenetv4,
197
+ title={MobileNetV4-Universal Models for the Mobile Ecosystem},
198
+ 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},
199
+ journal={arXiv preprint arXiv:2404.10518},
200
+ year={2024}
201
+ }
202
+ ```
203
+ ```bibtex
204
+ @misc{rw2019timm,
205
+ author = {Ross Wightman},
206
+ title = {PyTorch Image Models},
207
+ year = {2019},
208
+ publisher = {GitHub},
209
+ journal = {GitHub repository},
210
+ doi = {10.5281/zenodo.4414861},
211
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
212
+ }
213
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "mobilenetv4_conv_medium",
3
+ "num_classes": 1000,
4
+ "num_features": 960,
5
+ "pretrained_cfg": {
6
+ "tag": "e250_r384_in12k_ft_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 384,
11
+ 384
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bicubic",
15
+ "crop_pct": 1.0,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.485,
19
+ 0.456,
20
+ 0.406
21
+ ],
22
+ "std": [
23
+ 0.229,
24
+ 0.224,
25
+ 0.225
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 12,
30
+ 12
31
+ ],
32
+ "first_conv": "conv_stem",
33
+ "classifier": "classifier"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d92f9694cfbd814e967ef1d1d1b6e41e6a7d47b7f400e08f285a0de418a93011
3
+ size 39179184
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ecc3f5c6e3e2b38e65be95d1c469e85336b809e939422411d0bdf4efbfa8812
3
+ size 39300682