Update model config and README
Browse files- README.md +113 -2
- model.safetensors +3 -0
README.md
CHANGED
@@ -2,6 +2,117 @@
|
|
2 |
tags:
|
3 |
- image-classification
|
4 |
- timm
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
---
|
7 |
-
# Model card for beitv2_base_patch16_224.in1k_ft_in22k_in1k
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
tags:
|
3 |
- image-classification
|
4 |
- timm
|
5 |
+
library_name: timm
|
6 |
+
license: apache-2.0
|
7 |
+
datasets:
|
8 |
+
- imagenet-1k
|
9 |
+
- imagenet-1k
|
10 |
+
- imagenet-22k
|
11 |
---
|
12 |
+
# Model card for beitv2_base_patch16_224.in1k_ft_in22k_in1k
|
13 |
+
|
14 |
+
A BEiT-v2 image classification model. Trained on ImageNet-1k with self-supervised masked image modelling (MIM) using a VQ-KD encoder as a visual tokenizer (via OpenAI CLIP B/16 teacher). Fine-tuned on ImageNet-22k and then ImageNet-1k.
|
15 |
+
|
16 |
+
|
17 |
+
## Model Details
|
18 |
+
- **Model Type:** Image classification / feature backbone
|
19 |
+
- **Model Stats:**
|
20 |
+
- Params (M): 86.5
|
21 |
+
- GMACs: 17.6
|
22 |
+
- Activations (M): 23.9
|
23 |
+
- Image size: 224 x 224
|
24 |
+
- **Papers:**
|
25 |
+
- BEiT v2: Masked Image Modeling with Vector-Quantized Visual Tokenizers: https://arxiv.org/abs/2208.06366
|
26 |
+
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
|
27 |
+
- **Dataset:** ImageNet-1k
|
28 |
+
- **Pretrain Dataset:**
|
29 |
+
- ImageNet-1k
|
30 |
+
- ImageNet-22k
|
31 |
+
- **Original:** https://github.com/microsoft/unilm/tree/master/beit2
|
32 |
+
|
33 |
+
## Model Usage
|
34 |
+
### Image Classification
|
35 |
+
```python
|
36 |
+
from urllib.request import urlopen
|
37 |
+
from PIL import Image
|
38 |
+
import timm
|
39 |
+
|
40 |
+
img = Image.open(urlopen(
|
41 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
42 |
+
))
|
43 |
+
|
44 |
+
model = timm.create_model('beitv2_base_patch16_224.in1k_ft_in22k_in1k', pretrained=True)
|
45 |
+
model = model.eval()
|
46 |
+
|
47 |
+
# get model specific transforms (normalization, resize)
|
48 |
+
data_config = timm.data.resolve_model_data_config(model)
|
49 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
50 |
+
|
51 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
52 |
+
|
53 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
54 |
+
```
|
55 |
+
|
56 |
+
### Image Embeddings
|
57 |
+
```python
|
58 |
+
from urllib.request import urlopen
|
59 |
+
from PIL import Image
|
60 |
+
import timm
|
61 |
+
|
62 |
+
img = Image.open(urlopen(
|
63 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
64 |
+
))
|
65 |
+
|
66 |
+
model = timm.create_model(
|
67 |
+
'beitv2_base_patch16_224.in1k_ft_in22k_in1k',
|
68 |
+
pretrained=True,
|
69 |
+
num_classes=0, # remove classifier nn.Linear
|
70 |
+
)
|
71 |
+
model = model.eval()
|
72 |
+
|
73 |
+
# get model specific transforms (normalization, resize)
|
74 |
+
data_config = timm.data.resolve_model_data_config(model)
|
75 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
76 |
+
|
77 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
78 |
+
|
79 |
+
# or equivalently (without needing to set num_classes=0)
|
80 |
+
|
81 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
82 |
+
# output is unpooled, a (1, 197, 768) shaped tensor
|
83 |
+
|
84 |
+
output = model.forward_head(output, pre_logits=True)
|
85 |
+
# output is a (1, num_features) shaped tensor
|
86 |
+
```
|
87 |
+
|
88 |
+
## Model Comparison
|
89 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
90 |
+
|
91 |
+
## Citation
|
92 |
+
```bibtex
|
93 |
+
@article{peng2022beit,
|
94 |
+
title={Beit v2: Masked image modeling with vector-quantized visual tokenizers},
|
95 |
+
author={Peng, Zhiliang and Dong, Li and Bao, Hangbo and Ye, Qixiang and Wei, Furu},
|
96 |
+
journal={arXiv preprint arXiv:2208.06366},
|
97 |
+
year={2022}
|
98 |
+
}
|
99 |
+
```
|
100 |
+
```bibtex
|
101 |
+
@article{dosovitskiy2020vit,
|
102 |
+
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
|
103 |
+
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},
|
104 |
+
journal={ICLR},
|
105 |
+
year={2021}
|
106 |
+
}
|
107 |
+
```
|
108 |
+
```bibtex
|
109 |
+
@misc{rw2019timm,
|
110 |
+
author = {Ross Wightman},
|
111 |
+
title = {PyTorch Image Models},
|
112 |
+
year = {2019},
|
113 |
+
publisher = {GitHub},
|
114 |
+
journal = {GitHub repository},
|
115 |
+
doi = {10.5281/zenodo.4414861},
|
116 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
117 |
+
}
|
118 |
+
```
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cee7cf4f990c27987411d71ad9627235cfb7612ea9a80276cf72b1bef84cfe38
|
3 |
+
size 349869368
|