timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
90551a3
1 Parent(s): 2147ee4
Files changed (4) hide show
  1. README.md +197 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 mobilenetv3_large_100.ra4_e3600_r224_in1k
11
+
12
+ A MobileNet-V4 image classification model. Trained on ImageNet-1k by Ross Wightman.
13
+
14
+ Trained with `timm` scripts using hyper-parameters inspired by the MobileNet-V4 paper with `timm` enhancements.
15
+
16
+ NOTE: So far, these are the only known MNV4 weights. Official weights for Tensorflow models are unreleased.
17
+
18
+
19
+ ## Model Details
20
+ - **Model Type:** Image classification / feature backbone
21
+ - **Model Stats:**
22
+ - Params (M): 5.5
23
+ - GMACs: 0.2
24
+ - Activations (M): 4.4
25
+ - Image size: train = 224 x 224, test = 256 x 256
26
+ - **Dataset:** ImageNet-1k
27
+ - **Original:** https://github.com/tensorflow/models/tree/master/official/vision
28
+ - **Papers:**
29
+ - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
30
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
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('mobilenetv3_large_100.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
+ 'mobilenetv3_large_100.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, 16, 112, 112])
82
+ # torch.Size([1, 24, 56, 56])
83
+ # torch.Size([1, 40, 28, 28])
84
+ # torch.Size([1, 112, 14, 14])
85
+ # torch.Size([1, 960, 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
+ 'mobilenetv3_large_100.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, 960, 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
+ | [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 |
162
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) | 79.364 | 94.754 | 5.29 | 256 |
163
+ | [mobilenetv4_conv_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r224_in1k) | 79.094 | 94.77 | 9.72 | 224 |
164
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) | 78.584 | 94.338 | 5.29 | 224 |
165
+ | [mobilenetv1_125.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_125.ra4_e3600_r224_in1k) | 77.600 | 93.804 | 6.27 | 256 |
166
+ | [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 |
167
+ | [mobilenetv1_125.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_125.ra4_e3600_r224_in1k) | 76.924 | 93.234 | 6.27 | 224 |
168
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) | 76.596 | 93.272 | 5.28 | 256 |
169
+ | [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 |
170
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) | 76.094 | 93.004 | 4.23 | 256 |
171
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) | 75.662 | 92.504 | 5.28 | 224 |
172
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) | 75.382 | 92.312 | 4.23 | 224 |
173
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) | 74.616 | 92.072 | 3.77 | 256 |
174
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) | 74.292 | 92.116 | 3.77 | 256 |
175
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) | 73.756 | 91.422 | 3.77 | 224 |
176
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) | 73.454 | 91.34 | 3.77 | 224 |
177
+
178
+ ## Citation
179
+ ```bibtex
180
+ @article{qin2024mobilenetv4,
181
+ title={MobileNetV4-Universal Models for the Mobile Ecosystem},
182
+ 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},
183
+ journal={arXiv preprint arXiv:2404.10518},
184
+ year={2024}
185
+ }
186
+ ```
187
+ ```bibtex
188
+ @misc{rw2019timm,
189
+ author = {Ross Wightman},
190
+ title = {PyTorch Image Models},
191
+ year = {2019},
192
+ publisher = {GitHub},
193
+ journal = {GitHub repository},
194
+ doi = {10.5281/zenodo.4414861},
195
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
196
+ }
197
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "mobilenetv3_large_100",
3
+ "num_classes": 1000,
4
+ "num_features": 960,
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
+ 256,
16
+ 256
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.95,
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": "conv_stem",
39
+ "classifier": "classifier"
40
+ }
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd595a2d59301fc6264c4aabb203f93ec17b0aa7bdd7532c8d9e1cf07dfc9bdc
3
+ size 22058008
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25d68e0ceecbae5f6952514b27f66745b7604aeabe94b02b60e085f8c3e536d4
3
+ size 22134058