Add model
Browse files- README.md +156 -0
- config.json +33 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
- transformers
|
6 |
+
library_name: timm
|
7 |
+
license: apache-2.0
|
8 |
+
datasets:
|
9 |
+
- imagenet-22k
|
10 |
+
- text_documents-160gb
|
11 |
+
- laion-400m
|
12 |
+
- coyo-700m
|
13 |
+
- cc15m
|
14 |
+
---
|
15 |
+
# Model card for beit3_base_patch16_224.pt
|
16 |
+
|
17 |
+
A BEiT-3 image classification model. Multimodal model pretrained on ImageNet-22k images, 160GB text documents, and web-scale image-text pairs with masked data modeling. Converted for vision-only classification tasks.
|
18 |
+
|
19 |
+
|
20 |
+
## Model Details
|
21 |
+
- **Model Type:** Image classification / feature backbone
|
22 |
+
- **Model Stats:**
|
23 |
+
- Params (M): 85.9
|
24 |
+
- GMACs: 17.6
|
25 |
+
- Activations (M): 23.9
|
26 |
+
- Image size: 224 x 224
|
27 |
+
- **Papers:**
|
28 |
+
- BEiT-3: Image as a Foreign Language: BEiT Pretraining for Vision and Vision-Language Tasks: https://arxiv.org/abs/2208.10442
|
29 |
+
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
|
30 |
+
- **Dataset:**
|
31 |
+
- ImageNet-22k
|
32 |
+
- Text_documents-160GB
|
33 |
+
- LAION-400M
|
34 |
+
- COYO-700M
|
35 |
+
- CC15M
|
36 |
+
- **Original:** https://github.com/microsoft/unilm/tree/master/beit3
|
37 |
+
|
38 |
+
## Model Usage
|
39 |
+
### Image Classification
|
40 |
+
```python
|
41 |
+
from urllib.request import urlopen
|
42 |
+
from PIL import Image
|
43 |
+
import timm
|
44 |
+
|
45 |
+
img = Image.open(urlopen(
|
46 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
47 |
+
))
|
48 |
+
|
49 |
+
model = timm.create_model('beit3_base_patch16_224.pt', pretrained=True)
|
50 |
+
model = model.eval()
|
51 |
+
|
52 |
+
# get model specific transforms (normalization, resize)
|
53 |
+
data_config = timm.data.resolve_model_data_config(model)
|
54 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
55 |
+
|
56 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
57 |
+
|
58 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
59 |
+
```
|
60 |
+
|
61 |
+
### Feature Map Extraction
|
62 |
+
```python
|
63 |
+
from urllib.request import urlopen
|
64 |
+
from PIL import Image
|
65 |
+
import timm
|
66 |
+
|
67 |
+
img = Image.open(urlopen(
|
68 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
69 |
+
))
|
70 |
+
|
71 |
+
model = timm.create_model(
|
72 |
+
'beit3_base_patch16_224.pt',
|
73 |
+
pretrained=True,
|
74 |
+
features_only=True,
|
75 |
+
)
|
76 |
+
model = model.eval()
|
77 |
+
|
78 |
+
# get model specific transforms (normalization, resize)
|
79 |
+
data_config = timm.data.resolve_model_data_config(model)
|
80 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
81 |
+
|
82 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
83 |
+
|
84 |
+
for o in output:
|
85 |
+
# print shape of each feature map in output
|
86 |
+
# e.g.:
|
87 |
+
# torch.Size([1, 768, 14, 14])
|
88 |
+
# torch.Size([1, 768, 14, 14])
|
89 |
+
# torch.Size([1, 768, 14, 14])
|
90 |
+
|
91 |
+
print(o.shape)
|
92 |
+
```
|
93 |
+
|
94 |
+
### Image Embeddings
|
95 |
+
```python
|
96 |
+
from urllib.request import urlopen
|
97 |
+
from PIL import Image
|
98 |
+
import timm
|
99 |
+
|
100 |
+
img = Image.open(urlopen(
|
101 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
102 |
+
))
|
103 |
+
|
104 |
+
model = timm.create_model(
|
105 |
+
'beit3_base_patch16_224.pt',
|
106 |
+
pretrained=True,
|
107 |
+
num_classes=0, # remove classifier nn.Linear
|
108 |
+
)
|
109 |
+
model = model.eval()
|
110 |
+
|
111 |
+
# get model specific transforms (normalization, resize)
|
112 |
+
data_config = timm.data.resolve_model_data_config(model)
|
113 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
114 |
+
|
115 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
116 |
+
|
117 |
+
# or equivalently (without needing to set num_classes=0)
|
118 |
+
|
119 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
120 |
+
# output is unpooled, a (1, 197, 768) shaped tensor
|
121 |
+
|
122 |
+
output = model.forward_head(output, pre_logits=True)
|
123 |
+
# output is a (1, num_features) shaped tensor
|
124 |
+
```
|
125 |
+
|
126 |
+
## Model Comparison
|
127 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
128 |
+
|
129 |
+
## Citation
|
130 |
+
```bibtex
|
131 |
+
@article{wang2022beit3,
|
132 |
+
title={Image as a foreign language: Beit pretraining for vision and vision-language tasks},
|
133 |
+
author={Wang, Wenhui and Bao, Hangbo and Dong, Li and Bjorck, Johan and Peng, Zhiliang and Liu, Qiang and Aggarwal, Kriti and Mohammed, Owais Khan and Singhal, Saksham and Som, Subhojit and others},
|
134 |
+
journal={arXiv preprint arXiv:2208.10442},
|
135 |
+
year={2022}
|
136 |
+
}
|
137 |
+
```
|
138 |
+
```bibtex
|
139 |
+
@article{dosovitskiy2020vit,
|
140 |
+
title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
|
141 |
+
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},
|
142 |
+
journal={ICLR},
|
143 |
+
year={2021}
|
144 |
+
}
|
145 |
+
```
|
146 |
+
```bibtex
|
147 |
+
@misc{rw2019timm,
|
148 |
+
author = {Ross Wightman},
|
149 |
+
title = {PyTorch Image Models},
|
150 |
+
year = {2019},
|
151 |
+
publisher = {GitHub},
|
152 |
+
journal = {GitHub repository},
|
153 |
+
doi = {10.5281/zenodo.4414861},
|
154 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
155 |
+
}
|
156 |
+
```
|
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "beit3_base_patch16_224",
|
3 |
+
"num_classes": 0,
|
4 |
+
"num_features": 768,
|
5 |
+
"global_pool": "avg",
|
6 |
+
"pretrained_cfg": {
|
7 |
+
"tag": "pt",
|
8 |
+
"custom_load": false,
|
9 |
+
"input_size": [
|
10 |
+
3,
|
11 |
+
224,
|
12 |
+
224
|
13 |
+
],
|
14 |
+
"fixed_input_size": true,
|
15 |
+
"interpolation": "bicubic",
|
16 |
+
"crop_pct": 1.0,
|
17 |
+
"crop_mode": "center",
|
18 |
+
"mean": [
|
19 |
+
0.485,
|
20 |
+
0.456,
|
21 |
+
0.406
|
22 |
+
],
|
23 |
+
"std": [
|
24 |
+
0.229,
|
25 |
+
0.224,
|
26 |
+
0.225
|
27 |
+
],
|
28 |
+
"num_classes": 0,
|
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:ff06b61d58210de08234f4744b781c4b68071647ec1207aba56f9f9f80c2a774
|
3 |
+
size 343581672
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:79b5034f9fc1a3f8a2859be36d1470874e299d700fd8e20c7d8a1695d29cac48
|
3 |
+
size 343634722
|