timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
3788746
1 Parent(s): cb74c1f
Files changed (4) hide show
  1. README.md +195 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 efficientnet_b0.ra4_e3600_r224_in1k
11
+
12
+ A EfficientNet 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 with `timm` enhancements.
15
+
16
+
17
+
18
+ ## Model Details
19
+ - **Model Type:** Image classification / feature backbone
20
+ - **Model Stats:**
21
+ - Params (M): 5.3
22
+ - GMACs: 0.4
23
+ - Activations (M): 6.7
24
+ - Image size: train = 224 x 224, test = 256 x 256
25
+ - **Dataset:** ImageNet-1k
26
+ - **Papers:**
27
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
28
+ - EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks: https://arxiv.org/abs/1905.11946
29
+ - MobileNetV4 -- Universal Models for the Mobile Ecosystem: https://arxiv.org/abs/2404.10518
30
+ - **Original:** https://github.com/tensorflow/models/tree/master/official/vision
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('efficientnet_b0.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
+ 'efficientnet_b0.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, 320, 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
+ 'efficientnet_b0.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, 1280, 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 |top1_err|top5 |top5_err|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 |15.01 |97.294|2.706 |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|15.228 |97.344|2.656 |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 |15.36 |97.114|2.886 |32.59 |448 |
130
+ | [mobilenetv4_hybrid_large.ix_e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.ix_e600_r384_in1k) |84.356|15.644 |96.892 |3.108 |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|15.686 |97.102|2.898 |32.59 |384 |
132
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) |84.266|15.734 |96.936 |3.064 |37.76 |448 |
133
+ | [mobilenetv4_hybrid_large.ix_e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.ix_e600_r384_in1k) |83.990|16.010 |96.702 |3.298 |37.76 |384 |
134
+ | [mobilenetv4_conv_aa_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e600_r384_in1k) |83.824|16.176 |96.734|3.266 |32.59 |480 |
135
+ | [mobilenetv4_hybrid_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_large.e600_r384_in1k) |83.800|16.200 |96.770 |3.230 |37.76 |384 |
136
+ | [mobilenetv4_hybrid_medium.ix_e550_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k) |83.394|16.606 |96.760|3.240 |11.07 |448 |
137
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) |83.392|16.608 |96.622 |3.378 |32.59 |448 |
138
+ | [mobilenetv4_conv_aa_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_aa_large.e600_r384_in1k) |83.244|16.756 |96.392|3.608 |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 |17.01 |96.67 |3.33 |11.07 |320 |
140
+ | [mobilenetv4_hybrid_medium.ix_e550_r384_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r384_in1k) |82.968|17.032 |96.474|3.526 |11.07 |384 |
141
+ | [mobilenetv4_conv_large.e600_r384_in1k](http://hf.co/timm/mobilenetv4_conv_large.e600_r384_in1k) |82.952|17.048 |96.266 |3.734 |32.59 |384 |
142
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) |82.674|17.326 |96.31 |3.69 |32.59 |320 |
143
+ | [mobilenetv4_hybrid_medium.ix_e550_r256_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r256_in1k) |82.492|17.508 |96.278|3.722 |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|17.636 |96.256|3.744 |11.07 |256 |
145
+ | [mobilenetv4_conv_large.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_large.e500_r256_in1k) |81.862|18.138 |95.69 |4.31 |32.59 |256 |
146
+ | [mobilenetv4_hybrid_medium.ix_e550_r256_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.ix_e550_r256_in1k) |81.446|18.554 |95.704|4.296 |11.07 |256 |
147
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) |81.276|18.724 |95.742|4.258 |11.07 |256 |
148
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) |80.858|19.142 |95.768|4.232 |9.72 |320 |
149
+ | [mobilenetv4_hybrid_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_hybrid_medium.e500_r224_in1k) |80.442|19.558 |95.38 |4.62 |11.07 |224 |
150
+ | [mobilenetv4_conv_blur_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_blur_medium.e500_r224_in1k) |80.142|19.858 |95.298|4.702 |9.72 |256 |
151
+ | [mobilenetv4_conv_medium.e500_r256_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r256_in1k) |79.928|20.072 |95.184|4.816 |9.72 |256 |
152
+ | [mobilenetv4_conv_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r224_in1k) |79.808|20.192 |95.186|4.814 |9.72 |256 |
153
+ | [mobilenetv4_conv_blur_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_blur_medium.e500_r224_in1k) |79.438|20.562 |94.932|5.068 |9.72 |224 |
154
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) |79.364|20.636 |94.754|5.246 |5.29 |256 |
155
+ | [mobilenetv4_conv_medium.e500_r224_in1k](http://hf.co/timm/mobilenetv4_conv_medium.e500_r224_in1k) |79.094|20.906 |94.77 |5.23 |9.72 |224 |
156
+ | [efficientnet_b0.ra4_e3600_r224_in1k](http://hf.co/timm/efficientnet_b0.ra4_e3600_r224_in1k) |78.584|21.416 |94.338|5.662 |5.29 |224 |
157
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) |76.596|23.404 |93.272|6.728 |5.28 |256 |
158
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) |76.094|23.906 |93.004|6.996 |4.23 |256 |
159
+ | [mobilenetv1_100h.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100h.ra4_e3600_r224_in1k) |75.662|24.338 |92.504|7.496 |5.28 |224 |
160
+ | [mobilenetv1_100.ra4_e3600_r224_in1k](http://hf.co/timm/mobilenetv1_100.ra4_e3600_r224_in1k) |75.382|24.618 |92.312|7.688 |4.23 |224 |
161
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) |74.616|25.384 |92.072|7.928 |3.77 |256 |
162
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) |74.292|25.708 |92.116|7.884 |3.77 |256 |
163
+ | [mobilenetv4_conv_small.e2400_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e2400_r224_in1k) |73.756|26.244 |91.422|8.578 |3.77 |224 |
164
+ | [mobilenetv4_conv_small.e1200_r224_in1k](http://hf.co/timm/mobilenetv4_conv_small.e1200_r224_in1k) |73.454|26.546 |91.34 |8.66 |3.77 |224 |
165
+
166
+ ## Citation
167
+ ```bibtex
168
+ @misc{rw2019timm,
169
+ author = {Ross Wightman},
170
+ title = {PyTorch Image Models},
171
+ year = {2019},
172
+ publisher = {GitHub},
173
+ journal = {GitHub repository},
174
+ doi = {10.5281/zenodo.4414861},
175
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
176
+ }
177
+ ```
178
+ ```bibtex
179
+ @inproceedings{tan2019efficientnet,
180
+ title={Efficientnet: Rethinking model scaling for convolutional neural networks},
181
+ author={Tan, Mingxing and Le, Quoc},
182
+ booktitle={International conference on machine learning},
183
+ pages={6105--6114},
184
+ year={2019},
185
+ organization={PMLR}
186
+ }
187
+ ```
188
+ ```bibtex
189
+ @article{qin2024mobilenetv4,
190
+ title={MobileNetV4-Universal Models for the Mobile Ecosystem},
191
+ 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},
192
+ journal={arXiv preprint arXiv:2404.10518},
193
+ year={2024}
194
+ }
195
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "efficientnet_b0",
3
+ "num_classes": 1000,
4
+ "num_features": 1280,
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.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": "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:b92c4ed884e3d1509dcc45996e2a581608f1ca0d52fae9006f4c2ed292b90bde
3
+ size 21355344
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ac601c3eac9f435eed489244ab0d5b8a5a842c904d24ae4f08dfcfc382bcad8
3
+ size 21445482