timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
5bbc78b
1 Parent(s): 7913b10

Update model config and README

Browse files
Files changed (2) hide show
  1. README.md +110 -2
  2. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,114 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
 
6
  ---
7
- # Model card for vit_small_patch16_224.augreg_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
10
  ---
11
+ # Model card for vit_small_patch16_224.augreg_in21k_ft_in1k
12
+
13
+ A Vision Transformer (ViT) image classification model. Trained on ImageNet-21k and fine-tuned on ImageNet-1k (with additional augmentation and regularization) in JAX by paper authors, ported to PyTorch by Ross Wightman.
14
+
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 22.1
20
+ - GMACs: 4.3
21
+ - Activations (M): 8.2
22
+ - Image size: 224 x 224
23
+ - **Papers:**
24
+ - How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers: https://arxiv.org/abs/2106.10270
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
28
+ - **Original:** https://github.com/google-research/vision_transformer
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_small_patch16_224.augreg_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_small_patch16_224.augreg_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, 384) 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
+ @article{steiner2021augreg,
91
+ title={How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers},
92
+ author={Steiner, Andreas and Kolesnikov, Alexander and and Zhai, Xiaohua and Wightman, Ross and Uszkoreit, Jakob and Beyer, Lucas},
93
+ journal={arXiv preprint arXiv:2106.10270},
94
+ year={2021}
95
+ }
96
+ ```
97
+ ```bibtex
98
+ @article{dosovitskiy2020vit,
99
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
100
+ 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},
101
+ journal={ICLR},
102
+ year={2021}
103
+ }
104
+ ```
105
+ ```bibtex
106
+ @misc{rw2019timm,
107
+ author = {Ross Wightman},
108
+ title = {PyTorch Image Models},
109
+ year = {2019},
110
+ publisher = {GitHub},
111
+ journal = {GitHub repository},
112
+ doi = {10.5281/zenodo.4414861},
113
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
114
+ }
115
+ ```
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79c03c635cdfd798a364a9d8c4e5c0b7255b975ea2c9616046d4f77ab01435aa
3
+ size 88216496