timm
/

Image Classification
timm
PyTorch
Safetensors
Transformers
rwightman HF staff commited on
Commit
7abfd86
·
1 Parent(s): c35e0b1

Update model config and README

Browse files
Files changed (2) hide show
  1. README.md +112 -2
  2. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,116 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
 
6
  ---
7
- # Model card for vit_base_patch16_224_miil.in21k_ft_in1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  tags:
3
  - image-classification
4
  - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-21k-p
10
  ---
11
+ # Model card for vit_base_patch16_224_miil.in21k_ft_in1k
12
+
13
+ A Vision Transformer (ViT) image classification model. Petrained on ImageNet-21k-P and fine-tuned on ImageNet-1k by Alibaba MIIL.
14
+
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 86.5
20
+ - GMACs: 16.9
21
+ - Activations (M): 16.5
22
+ - Image size: 224 x 224
23
+ - **Papers:**
24
+ - ImageNet-21K Pretraining for the Masses: https://arxiv.org/abs/2104.10972
25
+ - An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
26
+ - **Dataset:** ImageNet-1k
27
+ - **Pretrain Dataset:** ImageNet-21k-P
28
+ - **Original:** https://github.com/Alibaba-MIIL/ImageNet21K
29
+
30
+ ## Model Usage
31
+ ### Image Classification
32
+ ```python
33
+ from urllib.request import urlopen
34
+ from PIL import Image
35
+ import timm
36
+
37
+ img = Image.open(urlopen(
38
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
39
+ ))
40
+
41
+ model = timm.create_model('vit_base_patch16_224_miil.in21k_ft_in1k', pretrained=True)
42
+ model = model.eval()
43
+
44
+ # get model specific transforms (normalization, resize)
45
+ data_config = timm.data.resolve_model_data_config(model)
46
+ transforms = timm.data.create_transform(**data_config, is_training=False)
47
+
48
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
49
+
50
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
51
+ ```
52
+
53
+ ### Image Embeddings
54
+ ```python
55
+ from urllib.request import urlopen
56
+ from PIL import Image
57
+ import timm
58
+
59
+ img = Image.open(urlopen(
60
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
61
+ ))
62
+
63
+ model = timm.create_model(
64
+ 'vit_base_patch16_224_miil.in21k_ft_in1k',
65
+ pretrained=True,
66
+ num_classes=0, # remove classifier nn.Linear
67
+ )
68
+ model = model.eval()
69
+
70
+ # get model specific transforms (normalization, resize)
71
+ data_config = timm.data.resolve_model_data_config(model)
72
+ transforms = timm.data.create_transform(**data_config, is_training=False)
73
+
74
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
75
+
76
+ # or equivalently (without needing to set num_classes=0)
77
+
78
+ output = model.forward_features(transforms(img).unsqueeze(0))
79
+ # output is unpooled, a (1, 197, 768) shaped tensor
80
+
81
+ output = model.forward_head(output, pre_logits=True)
82
+ # output is a (1, num_features) shaped tensor
83
+ ```
84
+
85
+ ## Model Comparison
86
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
87
+
88
+ ## Citation
89
+ ```bibtex
90
+ @misc{ridnik2021imagenet21k,
91
+ title={ImageNet-21K Pretraining for the Masses},
92
+ author={Tal Ridnik and Emanuel Ben-Baruch and Asaf Noy and Lihi Zelnik-Manor},
93
+ year={2021},
94
+ eprint={2104.10972},
95
+ archivePrefix={arXiv},
96
+ primaryClass={cs.CV}
97
+ }
98
+ ```
99
+ ```bibtex
100
+ @article{dosovitskiy2020vit,
101
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
102
+ 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},
103
+ journal={ICLR},
104
+ year={2021}
105
+ }
106
+ ```
107
+ ```bibtex
108
+ @misc{rw2019timm,
109
+ author = {Ross Wightman},
110
+ title = {PyTorch Image Models},
111
+ year = {2019},
112
+ publisher = {GitHub},
113
+ journal = {GitHub repository},
114
+ doi = {10.5281/zenodo.4414861},
115
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
116
+ }
117
+ ```
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9899698b305e6b032b17fe98a6f436447d966e27c90c92423087ae175bba0da0
3
+ size 346173018