timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
c0c8326
1 Parent(s): 689b116

Update model config and README

Browse files
Files changed (2) hide show
  1. README.md +108 -2
  2. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,112 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for vit_relpos_small_patch16_224.sw_in1k
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  tags:
3
  - image-classification
4
  - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
  ---
10
+ # Model card for vit_relpos_small_patch16_224.sw_in1k
11
+
12
+ A Vision Transformer (ViT) image classification model. This is a `timm` specific variation of the ViT architecture with relative position embeddings, no class token, and final representation via global average pool of tokens. Trained on ImageNet-1k in `timm` using recipe template described below.
13
+
14
+ Recipe details:
15
+ * Based on Swin Transformer train / pretrain recipe with modifications (related to both DeiT and ConvNeXt recipes)
16
+ * AdamW optimizer, gradient clipping, EMA weight averaging
17
+ * Cosine LR schedule with warmup
18
+
19
+
20
+ ## Model Details
21
+ - **Model Type:** Image classification / feature backbone
22
+ - **Model Stats:**
23
+ - Params (M): 22.0
24
+ - GMACs: 4.2
25
+ - Activations (M): 9.4
26
+ - Image size: 224 x 224
27
+ - **Papers:**
28
+ - @: i
29
+ - An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale: https://arxiv.org/abs/2010.11929v2
30
+ - **Dataset:** ImageNet-1k
31
+ - **Original:** https://github.com/huggingface/pytorch-image-models
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('vit_relpos_small_patch16_224.sw_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
+ 'vit_relpos_small_patch16_224.sw_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, 196, 384) 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
+ @misc{rw2019timm,
94
+ author = {Ross Wightman},
95
+ title = {PyTorch Image Models},
96
+ year = {2019},
97
+ publisher = {GitHub},
98
+ journal = {GitHub repository},
99
+ doi = {10.5281/zenodo.4414861},
100
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
101
+ }
102
+ ```
103
+ ```bibtex
104
+ n
105
+ ```
106
+ ```bibtex
107
+ @article{dosovitskiy2020vit,
108
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
109
+ 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},
110
+ journal={ICLR},
111
+ year={2021}
112
+ }
113
+ ```
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f654e79425b7e5c2d578b2a28efe5c202c6f61a1660cbb619bc94f6e46da25e
3
+ size 87955300