timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
a003d4b
1 Parent(s): f6324ef

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 gc_efficientnetv2_rw_t.agc_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 gc_efficientnetv2_rw_t.agc_in1k
11
+
12
+ A GC-EfficientNet-v2 image classification model with Global Context attention. This is a `timm` specific variation of the architecture. Trained on ImageNet-1k in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * Based on [ResNet Strikes Back](https://arxiv.org/abs/2110.00476) `C` recipes
16
+ * SGD (w/ Nesterov) optimizer and AGC (adaptive gradient clipping).
17
+ * Cosine LR schedule with warmup
18
+
19
+
20
+ ## Model Details
21
+ - **Model Type:** Image classification / feature backbone
22
+ - **Model Stats:**
23
+ - Params (M): 13.7
24
+ - GMACs: 1.9
25
+ - Activations (M): 10.0
26
+ - Image size: train = 224 x 224, test = 288 x 288
27
+ - **Papers:**
28
+ - EfficientNetV2: Smaller Models and Faster Training: https://arxiv.org/abs/2104.00298
29
+ - GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond: https://arxiv.org/abs/1904.11492
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('gc_efficientnetv2_rw_t.agc_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
+ 'gc_efficientnetv2_rw_t.agc_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, 112, 112])
84
+ # torch.Size([1, 40, 56, 56])
85
+ # torch.Size([1, 48, 28, 28])
86
+ # torch.Size([1, 128, 14, 14])
87
+ # torch.Size([1, 208, 7, 7])
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
+ 'gc_efficientnetv2_rw_t.agc_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, 1024, 7, 7) 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
+ @inproceedings{tan2021efficientnetv2,
130
+ title={Efficientnetv2: Smaller models and faster training},
131
+ author={Tan, Mingxing and Le, Quoc},
132
+ booktitle={International conference on machine learning},
133
+ pages={10096--10106},
134
+ year={2021},
135
+ organization={PMLR}
136
+ }
137
+ ```
138
+ ```bibtex
139
+ @misc{rw2019timm,
140
+ author = {Ross Wightman},
141
+ title = {PyTorch Image Models},
142
+ year = {2019},
143
+ publisher = {GitHub},
144
+ journal = {GitHub repository},
145
+ doi = {10.5281/zenodo.4414861},
146
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
147
+ }
148
+ ```
149
+ ```bibtex
150
+ @article{cao2019GCNet,
151
+ title={GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond},
152
+ author={Cao, Yue and Xu, Jiarui and Lin, Stephen and Wei, Fangyun and Hu, Han},
153
+ journal={arXiv preprint arXiv:1904.11492},
154
+ year={2019}
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": 1024,
5
  "pretrained_cfg": {
 
6
  "custom_load": false,
7
  "input_size": [
8
  3,
 
3
  "num_classes": 1000,
4
  "num_features": 1024,
5
  "pretrained_cfg": {
6
+ "tag": "agc_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:c1625afa00627e21f6cc281a60b38abfaa5fbca47159f2f64cbf964c5d6d80ba
3
+ size 55270248