timm
/

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