Add model
Browse files- README.md +163 -0
- config.json +35 -0
- model.safetensors +3 -0
- 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_152x2_bit.goog_teacher_in21k_ft_in1k_384
|
12 |
+
|
13 |
+
A ResNet-V2-BiT (Big Transfer w/ pre-activation ResNet) image classification model. Pretrained on ImageNet-21k and fine-tuned 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): 236.3
|
23 |
+
- GMACs: 136.2
|
24 |
+
- Activations (M): 132.6
|
25 |
+
- Image size: 384 x 384
|
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_152x2_bit.goog_teacher_in21k_ft_in1k_384', 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_152x2_bit.goog_teacher_in21k_ft_in1k_384',
|
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, 128, 192, 192])
|
84 |
+
# torch.Size([1, 512, 96, 96])
|
85 |
+
# torch.Size([1, 1024, 48, 48])
|
86 |
+
# torch.Size([1, 2048, 24, 24])
|
87 |
+
# torch.Size([1, 4096, 12, 12])
|
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_152x2_bit.goog_teacher_in21k_ft_in1k_384',
|
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, 4096, 12, 12) 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_152x2_bit",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 4096,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "goog_teacher_in21k_ft_in1k_384",
|
7 |
+
"custom_load": true,
|
8 |
+
"input_size": [
|
9 |
+
3,
|
10 |
+
384,
|
11 |
+
384
|
12 |
+
],
|
13 |
+
"fixed_input_size": false,
|
14 |
+
"interpolation": "bicubic",
|
15 |
+
"crop_pct": 1.0,
|
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 |
+
12,
|
30 |
+
12
|
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:b6250a9e9943038c1c18a8cc747e753c8cc1f1478375df97336ebec9dc9942e0
|
3 |
+
size 945387832
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4a70a45429f64ca2d1a258e7190d6df35476c6b7df4b95772f31d233de799314
|
3 |
+
size 945521337
|