Add model
Browse files- README.md +188 -0
- config.json +33 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
library_name: timm
|
6 |
+
license: apache-2.0
|
7 |
+
datasets:
|
8 |
+
- imagenet-1k
|
9 |
+
- imagenet-12k
|
10 |
+
---
|
11 |
+
# Model card for vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k
|
12 |
+
|
13 |
+
A Vision Transformer (ViT) image classification model. This is a `timm` specific variation of the architecture with registers, global average pooling.
|
14 |
+
|
15 |
+
There are a number of models in the lower end of model scales that originate in `timm`:
|
16 |
+
|
17 |
+
| variant | width | mlp width (mult) | heads | depth | timm orig |
|
18 |
+
| ------- | ----- | ---------------- | ----- | ----- | ---- |
|
19 |
+
| tiny | 192 | 768 (4) | 3 | 12 | n |
|
20 |
+
| wee | 256 | 1280 (5) | 4 | 14 | y |
|
21 |
+
| pwee | 256 | 1280 (5) | 4 | 16 (parallel) | y |
|
22 |
+
| small | 384 | 1536 (4) | 6 | 12 | n |
|
23 |
+
| little | 320 | 1792 (5.6) | 5 | 14 | y |
|
24 |
+
| medium | 512 | 2048 (4) | 8 | 12 | y |
|
25 |
+
| mediumd | 512 | 2048 (4) | 8 | 20 | y |
|
26 |
+
| betwixt | 640 | 2560 (4) | 10 | 12 | y |
|
27 |
+
| base | 768 | 3072 (4) | 12 | 12 | n |
|
28 |
+
|
29 |
+
Pretrained on ImageNet-12k and fine-tuned on ImageNet-1k by Ross Wightman in `timm` using recipe template described below.
|
30 |
+
|
31 |
+
Recipe details:
|
32 |
+
* Searching for better baselines. Influced by Swin/DeiT/DeiT-III but w/ increased weight decay, moderate (in12k) to high (in1k) augmentation. Layer-decay used for fine-tune. Some runs used BCE and/or NAdamW instead of AdamW.
|
33 |
+
* See [train_hparams.yaml](./train_hparams.yaml) for specifics of each model.
|
34 |
+
|
35 |
+
|
36 |
+
## Model Details
|
37 |
+
- **Model Type:** Image classification / feature backbone
|
38 |
+
- **Model Stats:**
|
39 |
+
- Params (M): 64.1
|
40 |
+
- GMACs: 16.5
|
41 |
+
- Activations (M): 24.1
|
42 |
+
- Image size: 256 x 256
|
43 |
+
- **Papers:**
|
44 |
+
- Vision Transformers Need Registers: https://arxiv.org/abs/2309.16588
|
45 |
+
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
|
46 |
+
- **Dataset:** ImageNet-1k
|
47 |
+
- **Pretrain Dataset:** ImageNet-12k
|
48 |
+
- **Original:** https://github.com/huggingface/pytorch-image-models
|
49 |
+
|
50 |
+
## Model Usage
|
51 |
+
### Image Classification
|
52 |
+
```python
|
53 |
+
from urllib.request import urlopen
|
54 |
+
from PIL import Image
|
55 |
+
import timm
|
56 |
+
|
57 |
+
img = Image.open(urlopen(
|
58 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
59 |
+
))
|
60 |
+
|
61 |
+
model = timm.create_model('vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k', pretrained=True)
|
62 |
+
model = model.eval()
|
63 |
+
|
64 |
+
# get model specific transforms (normalization, resize)
|
65 |
+
data_config = timm.data.resolve_model_data_config(model)
|
66 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
67 |
+
|
68 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
69 |
+
|
70 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
71 |
+
```
|
72 |
+
|
73 |
+
### Feature Map Extraction
|
74 |
+
```python
|
75 |
+
from urllib.request import urlopen
|
76 |
+
from PIL import Image
|
77 |
+
import timm
|
78 |
+
|
79 |
+
img = Image.open(urlopen(
|
80 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
81 |
+
))
|
82 |
+
|
83 |
+
model = timm.create_model(
|
84 |
+
'vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k',
|
85 |
+
pretrained=True,
|
86 |
+
features_only=True,
|
87 |
+
)
|
88 |
+
model = model.eval()
|
89 |
+
|
90 |
+
# get model specific transforms (normalization, resize)
|
91 |
+
data_config = timm.data.resolve_model_data_config(model)
|
92 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
93 |
+
|
94 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
95 |
+
|
96 |
+
for o in output:
|
97 |
+
# print shape of each feature map in output
|
98 |
+
# e.g.:
|
99 |
+
# torch.Size([1, 512, 16, 16])
|
100 |
+
# torch.Size([1, 512, 16, 16])
|
101 |
+
# torch.Size([1, 512, 16, 16])
|
102 |
+
|
103 |
+
print(o.shape)
|
104 |
+
```
|
105 |
+
|
106 |
+
### Image Embeddings
|
107 |
+
```python
|
108 |
+
from urllib.request import urlopen
|
109 |
+
from PIL import Image
|
110 |
+
import timm
|
111 |
+
|
112 |
+
img = Image.open(urlopen(
|
113 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
114 |
+
))
|
115 |
+
|
116 |
+
model = timm.create_model(
|
117 |
+
'vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k',
|
118 |
+
pretrained=True,
|
119 |
+
num_classes=0, # remove classifier nn.Linear
|
120 |
+
)
|
121 |
+
model = model.eval()
|
122 |
+
|
123 |
+
# get model specific transforms (normalization, resize)
|
124 |
+
data_config = timm.data.resolve_model_data_config(model)
|
125 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
126 |
+
|
127 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
128 |
+
|
129 |
+
# or equivalently (without needing to set num_classes=0)
|
130 |
+
|
131 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
132 |
+
# output is unpooled, a (1, 260, 512) shaped tensor
|
133 |
+
|
134 |
+
output = model.forward_head(output, pre_logits=True)
|
135 |
+
# output is a (1, num_features) shaped tensor
|
136 |
+
```
|
137 |
+
|
138 |
+
## Model Comparison
|
139 |
+
| model | top1 | top5 | param_count | img_size |
|
140 |
+
| -------------------------------------------------- | ------ | ------ | ----------- | -------- |
|
141 |
+
| [vit_mediumd_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k) | 87.438 | 98.256 | 64.11 | 384 |
|
142 |
+
| [vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k) | 86.608 | 97.934 | 64.11 | 256 |
|
143 |
+
| [vit_betwixt_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_384.sbb2_e200_in12k_ft_in1k) | 86.594 | 98.02 | 60.4 | 384 |
|
144 |
+
| [vit_mediumd_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_mediumd_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 86.202 | 97.874 | 64.11 | 256 |
|
145 |
+
| [vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb2_e200_in12k_ft_in1k) | 85.734 | 97.61 | 60.4 | 256 |
|
146 |
+
| [vit_betwixt_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 85.418 | 97.480 | 60.4 | 256 |
|
147 |
+
| [vit_medium_patch16_reg4_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_medium_patch16_reg4_gap_256.sbb_in12k_ft_in1k) | 84.930 | 97.386 | 38.88 | 256 |
|
148 |
+
| [vit_mediumd_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_mediumd_patch16_rope_reg1_gap_256.sbb_in1k) | 84.322 | 96.812 | 63.95 | 256 |
|
149 |
+
| [vit_betwixt_patch16_rope_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_rope_reg4_gap_256.sbb_in1k) | 83.906 | 96.684 | 60.23 | 256 |
|
150 |
+
| [vit_base_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_base_patch16_rope_reg1_gap_256.sbb_in1k) | 83.866 | 96.67 | 86.43 | 256 |
|
151 |
+
| [vit_medium_patch16_rope_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_rope_reg1_gap_256.sbb_in1k) | 83.81 | 96.824 | 38.74 | 256 |
|
152 |
+
| [vit_little_patch16_reg1_gap_256.sbb_in12k_ft_in1k](https://huggingface.co/timm/vit_little_patch16_reg1_gap_256.sbb_in12k_ft_in1k) | 83.774 | 96.972 | 22.52 | 256 |
|
153 |
+
| [vit_betwixt_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg4_gap_256.sbb_in1k) | 83.706 | 96.616 | 60.4 | 256 |
|
154 |
+
| [vit_betwixt_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_betwixt_patch16_reg1_gap_256.sbb_in1k) | 83.628 | 96.544 | 60.4 | 256 |
|
155 |
+
| [vit_medium_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_reg4_gap_256.sbb_in1k) | 83.47 | 96.622 | 38.88 | 256 |
|
156 |
+
| [vit_medium_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_medium_patch16_reg1_gap_256.sbb_in1k) | 83.462 | 96.548 | 38.88 | 256 |
|
157 |
+
| [vit_little_patch16_reg4_gap_256.sbb_in1k](https://huggingface.co/timm/vit_little_patch16_reg4_gap_256.sbb_in1k) | 82.514 | 96.262 | 22.52 | 256 |
|
158 |
+
| [vit_wee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_wee_patch16_reg1_gap_256.sbb_in1k) | 80.258 | 95.360 | 13.42 | 256 |
|
159 |
+
| [vit_pwee_patch16_reg1_gap_256.sbb_in1k](https://huggingface.co/timm/vit_pwee_patch16_reg1_gap_256.sbb_in1k) | 80.072 | 95.136 | 15.25 | 256 |
|
160 |
+
|
161 |
+
## Citation
|
162 |
+
```bibtex
|
163 |
+
@misc{rw2019timm,
|
164 |
+
author = {Ross Wightman},
|
165 |
+
title = {PyTorch Image Models},
|
166 |
+
year = {2019},
|
167 |
+
publisher = {GitHub},
|
168 |
+
journal = {GitHub repository},
|
169 |
+
doi = {10.5281/zenodo.4414861},
|
170 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
171 |
+
}
|
172 |
+
```
|
173 |
+
```bibtex
|
174 |
+
@article{darcet2023vision,
|
175 |
+
title={Vision Transformers Need Registers},
|
176 |
+
author={Darcet, Timoth{'e}e and Oquab, Maxime and Mairal, Julien and Bojanowski, Piotr},
|
177 |
+
journal={arXiv preprint arXiv:2309.16588},
|
178 |
+
year={2023}
|
179 |
+
}
|
180 |
+
```
|
181 |
+
```bibtex
|
182 |
+
@article{dosovitskiy2020vit,
|
183 |
+
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
|
184 |
+
author={Dosovitskiy, Alexey and Beyer, Lucas and Kolesnikov, Alexander and Weissenborn, Dirk and Zhai, Xiaohua and Unterthiner, Thomas and Dehghani, Mostafa and Minderer, Matthias and Heigold, Georg and Gelly, Sylvain and Uszkoreit, Jakob and Houlsby, Neil},
|
185 |
+
journal={ICLR},
|
186 |
+
year={2021}
|
187 |
+
}
|
188 |
+
```
|
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "vit_mediumd_patch16_reg4_gap_256",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 512,
|
5 |
+
"global_pool": "avg",
|
6 |
+
"pretrained_cfg": {
|
7 |
+
"tag": "sbb2_e200_in12k_ft_in1k",
|
8 |
+
"custom_load": false,
|
9 |
+
"input_size": [
|
10 |
+
3,
|
11 |
+
256,
|
12 |
+
256
|
13 |
+
],
|
14 |
+
"fixed_input_size": true,
|
15 |
+
"interpolation": "bicubic",
|
16 |
+
"crop_pct": 0.95,
|
17 |
+
"crop_mode": "center",
|
18 |
+
"mean": [
|
19 |
+
0.5,
|
20 |
+
0.5,
|
21 |
+
0.5
|
22 |
+
],
|
23 |
+
"std": [
|
24 |
+
0.5,
|
25 |
+
0.5,
|
26 |
+
0.5
|
27 |
+
],
|
28 |
+
"num_classes": 1000,
|
29 |
+
"pool_size": null,
|
30 |
+
"first_conv": "patch_embed.proj",
|
31 |
+
"classifier": "head"
|
32 |
+
}
|
33 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e558cf2f2d8bccbb4bd367cb126f0f74ce3274af3eb1417715168d5ca68fdce
|
3 |
+
size 256462704
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:19c330029fa7f4355f57d6f69e3a924ac8c25d890df84bda34de4488a52e5cc3
|
3 |
+
size 256540813
|