timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
d7f6603
1 Parent(s): 80f0f5d

Update model config and README

Browse files
Files changed (3) hide show
  1. README.md +113 -2
  2. config.json +1 -1
  3. model.safetensors +3 -0
README.md CHANGED
@@ -2,6 +2,117 @@
2
  tags:
3
  - image-classification
4
  - timm
5
- library_tag: timm
 
 
 
6
  ---
7
- # Model card for vit_base_patch16_rpn_224.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_base_patch16_rpn_224.sw_in1k
11
+
12
+ A Vision Transformer (ViT) image classification model. This is a `timm` specific variation of the architecture with residual post normalization blocks. 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): 86.5
24
+ - GMACs: 16.8
25
+ - Activations (M): 16.4
26
+ - Image size: 224 x 224
27
+ - **Papers:**
28
+ - Swin Transformer V2: Scaling Up Capacity and Resolution: https://arxiv.org/abs/2111.09883
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_base_patch16_rpn_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_base_patch16_rpn_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, 768) 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
+ @inproceedings{liu2021swinv2,
105
+ title={Swin Transformer V2: Scaling Up Capacity and Resolution},
106
+ author={Ze Liu and Han Hu and Yutong Lin and Zhuliang Yao and Zhenda Xie and Yixuan Wei and Jia Ning and Yue Cao and Zheng Zhang and Li Dong and Furu Wei and Baining Guo},
107
+ booktitle={International Conference on Computer Vision and Pattern Recognition (CVPR)},
108
+ year={2022}
109
+ }
110
+ ```
111
+ ```bibtex
112
+ @article{dosovitskiy2020vit,
113
+ title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
114
+ 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},
115
+ journal={ICLR},
116
+ year={2021}
117
+ }
118
+ ```
config.json CHANGED
@@ -4,7 +4,7 @@
4
  "num_features": 768,
5
  "global_pool": "avg",
6
  "pretrained_cfg": {
7
- "tag": "in1k",
8
  "custom_load": false,
9
  "input_size": [
10
  3,
 
4
  "num_features": 768,
5
  "global_pool": "avg",
6
  "pretrained_cfg": {
7
+ "tag": "sw_in1k",
8
  "custom_load": false,
9
  "input_size": [
10
  3,
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ffc0dce184f543393ca0271ff9636bb4534430795d387e2edaf98a1702d5e7f8
3
+ size 346166792