timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
4553095
1 Parent(s): 686e927

Update model config and README

Browse files
Files changed (3) hide show
  1. README.md +158 -2
  2. config.json +1 -0
  3. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,162 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for efficientnet_em.ra2_in1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_em.ra2_in1k
11
+
12
+ A EfficientNet-EdgeTPU image classification model. Trained on ImageNet-1k in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * RandAugment `RA2` recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
16
+ * RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
17
+ * Step (exponential decay w/ staircase) LR schedule with warmup
18
+
19
+
20
+ ## Model Details
21
+ - **Model Type:** Image classification / feature backbone
22
+ - **Model Stats:**
23
+ - Params (M): 6.9
24
+ - GMACs: 3.0
25
+ - Activations (M): 14.3
26
+ - Image size: 240 x 240
27
+ - **Papers:**
28
+ - Accelerator-aware Neural Network Design using AutoML: https://arxiv.org/abs/2003.02838
29
+ - EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks: https://arxiv.org/abs/1905.11946
30
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
31
+ - **Dataset:** ImageNet-1k
32
+ - **Original:** https://github.com/huggingface/pytorch-image-models
33
+
34
+ ## Model Usage
35
+ ### Image Classification
36
+ ```python
37
+ from urllib.request import urlopen
38
+ from PIL import Image
39
+ import timm
40
+
41
+ img = Image.open(urlopen(
42
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
43
+ ))
44
+
45
+ model = timm.create_model('efficientnet_em.ra2_in1k', pretrained=True)
46
+ model = model.eval()
47
+
48
+ # get model specific transforms (normalization, resize)
49
+ data_config = timm.data.resolve_model_data_config(model)
50
+ transforms = timm.data.create_transform(**data_config, is_training=False)
51
+
52
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
53
+
54
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
55
+ ```
56
+
57
+ ### Feature Map Extraction
58
+ ```python
59
+ from urllib.request import urlopen
60
+ from PIL import Image
61
+ import timm
62
+
63
+ img = Image.open(urlopen(
64
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
65
+ ))
66
+
67
+ model = timm.create_model(
68
+ 'efficientnet_em.ra2_in1k',
69
+ pretrained=True,
70
+ features_only=True,
71
+ )
72
+ model = model.eval()
73
+
74
+ # get model specific transforms (normalization, resize)
75
+ data_config = timm.data.resolve_model_data_config(model)
76
+ transforms = timm.data.create_transform(**data_config, is_training=False)
77
+
78
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
79
+
80
+ for o in output:
81
+ # print shape of each feature map in output
82
+ # e.g.:
83
+ # torch.Size([1, 24, 120, 120])
84
+ # torch.Size([1, 32, 60, 60])
85
+ # torch.Size([1, 48, 30, 30])
86
+ # torch.Size([1, 144, 15, 15])
87
+ # torch.Size([1, 192, 8, 8])
88
+
89
+ print(o.shape)
90
+ ```
91
+
92
+ ### Image Embeddings
93
+ ```python
94
+ from urllib.request import urlopen
95
+ from PIL import Image
96
+ import timm
97
+
98
+ img = Image.open(urlopen(
99
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
100
+ ))
101
+
102
+ model = timm.create_model(
103
+ 'efficientnet_em.ra2_in1k',
104
+ pretrained=True,
105
+ num_classes=0, # remove classifier nn.Linear
106
+ )
107
+ model = model.eval()
108
+
109
+ # get model specific transforms (normalization, resize)
110
+ data_config = timm.data.resolve_model_data_config(model)
111
+ transforms = timm.data.create_transform(**data_config, is_training=False)
112
+
113
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
114
+
115
+ # or equivalently (without needing to set num_classes=0)
116
+
117
+ output = model.forward_features(transforms(img).unsqueeze(0))
118
+ # output is unpooled, a (1, 1280, 8, 8) shaped tensor
119
+
120
+ output = model.forward_head(output, pre_logits=True)
121
+ # output is a (1, num_features) shaped tensor
122
+ ```
123
+
124
+ ## Model Comparison
125
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
126
+
127
+ ## Citation
128
+ ```bibtex
129
+ @article{gupta2020accelerator,
130
+ title={Accelerator-aware neural network design using automl},
131
+ author={Gupta, Suyog and Akin, Berkin},
132
+ journal={arXiv preprint arXiv:2003.02838},
133
+ year={2020}
134
+ }
135
+ ```
136
+ ```bibtex
137
+ @misc{rw2019timm,
138
+ author = {Ross Wightman},
139
+ title = {PyTorch Image Models},
140
+ year = {2019},
141
+ publisher = {GitHub},
142
+ journal = {GitHub repository},
143
+ doi = {10.5281/zenodo.4414861},
144
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
145
+ }
146
+ ```
147
+ ```bibtex
148
+ @inproceedings{tan2019efficientnet,
149
+ title={Efficientnet: Rethinking model scaling for convolutional neural networks},
150
+ author={Tan, Mingxing and Le, Quoc},
151
+ booktitle={International conference on machine learning},
152
+ pages={6105--6114},
153
+ year={2019},
154
+ organization={PMLR}
155
+ }
156
+ ```
157
+ ```bibtex
158
+ @inproceedings{wightman2021resnet,
159
+ title={ResNet strikes back: An improved training procedure in timm},
160
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
161
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
162
+ }
163
+ ```
config.json CHANGED
@@ -3,6 +3,7 @@
3
  "num_classes": 1000,
4
  "num_features": 1280,
5
  "pretrained_cfg": {
 
6
  "custom_load": false,
7
  "input_size": [
8
  3,
 
3
  "num_classes": 1000,
4
  "num_features": 1280,
5
  "pretrained_cfg": {
6
+ "tag": "ra2_in1k",
7
  "custom_load": false,
8
  "input_size": [
9
  3,
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d93dd795b8b1d93f18b4374cc853e79183c5cf2d165409d067ed932196552f5c
3
+ size 27904678