timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
595d876
1 Parent(s): 9c84f47
Files changed (4) hide show
  1. README.md +163 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-21k
10
+ ---
11
+ # Model card for resnetv2_50x1_bit.goog_distilled_in1k
12
+
13
+ A ResNet-V2-BiT (Big Transfer w/ pre-activation ResNet) image classification model. Distilled from ImageNet-21k pretrained teacher model on ImageNet-1k by paper authors.
14
+
15
+ This model uses:
16
+ * Group Normalization (GN) in combination with Weight Standardization (WS) instead of Batch Normalization (BN)..
17
+
18
+
19
+ ## Model Details
20
+ - **Model Type:** Image classification / feature backbone
21
+ - **Model Stats:**
22
+ - Params (M): 25.5
23
+ - GMACs: 4.2
24
+ - Activations (M): 11.1
25
+ - Image size: 224 x 224
26
+ - **Papers:**
27
+ - Knowledge distillation: A good teacher is patient and consistent: https://arxiv.org/abs/2106.05237
28
+ - Big Transfer (BiT): General Visual Representation Learning: https://arxiv.org/abs/1912.11370
29
+ - Identity Mappings in Deep Residual Networks: https://arxiv.org/abs/1603.05027
30
+ - **Dataset:** ImageNet-1k
31
+ - **Pretrain Dataset:** ImageNet-21k
32
+ - **Original:** https://github.com/google-research/big_transfer
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('resnetv2_50x1_bit.goog_distilled_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
+ 'resnetv2_50x1_bit.goog_distilled_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, 64, 112, 112])
84
+ # torch.Size([1, 256, 56, 56])
85
+ # torch.Size([1, 512, 28, 28])
86
+ # torch.Size([1, 1024, 14, 14])
87
+ # torch.Size([1, 2048, 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
+ 'resnetv2_50x1_bit.goog_distilled_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, 2048, 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{beyer2022knowledge,
130
+ title={Knowledge distillation: A good teacher is patient and consistent},
131
+ author={Beyer, Lucas and Zhai, Xiaohua and Royer, Am{'e}lie and Markeeva, Larisa and Anil, Rohan and Kolesnikov, Alexander},
132
+ booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
133
+ pages={10925--10934},
134
+ year={2022}
135
+ }
136
+ ```
137
+ ```bibtex
138
+ @inproceedings{Kolesnikov2019BigT,
139
+ title={Big Transfer (BiT): General Visual Representation Learning},
140
+ author={Alexander Kolesnikov and Lucas Beyer and Xiaohua Zhai and Joan Puigcerver and Jessica Yung and Sylvain Gelly and Neil Houlsby},
141
+ booktitle={European Conference on Computer Vision},
142
+ year={2019}
143
+ }
144
+ ```
145
+ ```bibtex
146
+ @article{He2016,
147
+ author = {Kaiming He and Xiangyu Zhang and Shaoqing Ren and Jian Sun},
148
+ title = {Identity Mappings in Deep Residual Networks},
149
+ journal = {arXiv preprint arXiv:1603.05027},
150
+ year = {2016}
151
+ }
152
+ ```
153
+ ```bibtex
154
+ @misc{rw2019timm,
155
+ author = {Ross Wightman},
156
+ title = {PyTorch Image Models},
157
+ year = {2019},
158
+ publisher = {GitHub},
159
+ journal = {GitHub repository},
160
+ doi = {10.5281/zenodo.4414861},
161
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
162
+ }
163
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "resnetv2_50x1_bit",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "goog_distilled_in1k",
7
+ "custom_load": true,
8
+ "input_size": [
9
+ 3,
10
+ 224,
11
+ 224
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bicubic",
15
+ "crop_pct": 0.875,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.5,
19
+ 0.5,
20
+ 0.5
21
+ ],
22
+ "std": [
23
+ 0.5,
24
+ 0.5,
25
+ 0.5
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 7,
30
+ 7
31
+ ],
32
+ "first_conv": "stem.conv",
33
+ "classifier": "head.fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8a84ddc4683b81fb691141c571960a6e64be1c50a3e543a62bd959bf43c98f3
3
+ size 102212646
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44246272ab801b5063cd04935ccc0d7eb2c4a011d8b608757cab402dd1157be8
3
+ size 102257521