timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
fd940e1
·
verified ·
1 Parent(s): 13ce76f
Files changed (4) hide show
  1. README.md +161 -0
  2. config.json +32 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_name: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-12k
10
+ ---
11
+ # Model card for hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k
12
+
13
+ A Hiera image classification model w/ resizeable abs-win position embeddings and layer-scale. Pretrained on ImageNet-12k and fine-tuned on ImageNet-1k by Ross Wightman using "Searching for better ViT baselines" recipe. Patch dropout used during training using Hiera mask units, appeared to make pos embed more generalizable to other resolutions.
14
+
15
+
16
+ ## Model Details
17
+ - **Model Type:** Image classification / feature backbone
18
+ - **Model Stats:**
19
+ - Params (M): 34.4
20
+ - GMACs: 7.7
21
+ - Activations (M): 21.2
22
+ - Image size: 256 x 256
23
+ - **Pretrain Dataset:** ImageNet-12k
24
+ - **Dataset:** ImageNet-1k
25
+ - **Papers:**
26
+ - Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles: https://arxiv.org/abs/2306.00989
27
+ - PyTorch Image Models: https://github.com/huggingface/pytorch-image-models
28
+ - Window Attention is Bugged: How not to Interpolate Position Embeddings: https://arxiv.org/abs/2311.05613
29
+ - **Original:** https://github.com/facebookresearch/hiera
30
+
31
+ ## Model Usage
32
+ ### Image Classification
33
+ ```python
34
+ from urllib.request import urlopen
35
+ from PIL import Image
36
+ import timm
37
+
38
+ img = Image.open(urlopen(
39
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
40
+ ))
41
+
42
+ model = timm.create_model('hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k', pretrained=True)
43
+ model = model.eval()
44
+
45
+ # get model specific transforms (normalization, resize)
46
+ data_config = timm.data.resolve_model_data_config(model)
47
+ transforms = timm.data.create_transform(**data_config, is_training=False)
48
+
49
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
50
+
51
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
52
+ ```
53
+
54
+ ### Feature Map Extraction
55
+ ```python
56
+ from urllib.request import urlopen
57
+ from PIL import Image
58
+ import timm
59
+
60
+ img = Image.open(urlopen(
61
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
62
+ ))
63
+
64
+ model = timm.create_model(
65
+ 'hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k',
66
+ pretrained=True,
67
+ features_only=True,
68
+ )
69
+ model = model.eval()
70
+
71
+ # get model specific transforms (normalization, resize)
72
+ data_config = timm.data.resolve_model_data_config(model)
73
+ transforms = timm.data.create_transform(**data_config, is_training=False)
74
+
75
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
76
+
77
+ for o in output:
78
+ # print shape of each feature map in output
79
+ # e.g.:
80
+ # torch.Size([1, 96, 64, 64])
81
+ # torch.Size([1, 192, 32, 32])
82
+ # torch.Size([1, 384, 16, 16])
83
+ # torch.Size([1, 768, 8, 8])
84
+
85
+ print(o.shape)
86
+ ```
87
+
88
+ ### Image Embeddings
89
+ ```python
90
+ from urllib.request import urlopen
91
+ from PIL import Image
92
+ import timm
93
+
94
+ img = Image.open(urlopen(
95
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
96
+ ))
97
+
98
+ model = timm.create_model(
99
+ 'hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k',
100
+ pretrained=True,
101
+ num_classes=0, # remove classifier nn.Linear
102
+ )
103
+ model = model.eval()
104
+
105
+ # get model specific transforms (normalization, resize)
106
+ data_config = timm.data.resolve_model_data_config(model)
107
+ transforms = timm.data.create_transform(**data_config, is_training=False)
108
+
109
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
110
+
111
+ # or equivalently (without needing to set num_classes=0)
112
+
113
+ output = model.forward_features(transforms(img).unsqueeze(0))
114
+ # output is unpooled, a (1, 64, 768) shaped tensor
115
+
116
+ output = model.forward_head(output, pre_logits=True)
117
+ # output is a (1, num_features) shaped tensor
118
+ ```
119
+
120
+ ## Model Comparison
121
+ ### By Top-1
122
+
123
+ |model |top1 |top5 |param_count|
124
+ |---------------------------------|------|------|-----------|
125
+ |hiera_huge_224.mae_in1k_ft_in1k |86.834|98.01 |672.78 |
126
+ |hiera_large_224.mae_in1k_ft_in1k |86.042|97.648|213.74 |
127
+ |hiera_base_plus_224.mae_in1k_ft_in1k|85.134|97.158|69.9 |
128
+ |hiera_small_abswin_256.sbb2_e200_in12k_ft_in1k |84.912|97.260|35.01 |
129
+ |hiera_small_abswin_256.sbb2_pd_e200_in12k_ft_in1k |84.560|97.106|35.01 |
130
+ |hiera_base_224.mae_in1k_ft_in1k |84.49 |97.032|51.52 |
131
+ |hiera_small_224.mae_in1k_ft_in1k |83.884|96.684|35.01 |
132
+ |hiera_tiny_224.mae_in1k_ft_in1k |82.786|96.204|27.91 |
133
+
134
+ ## Citation
135
+ ```bibtex
136
+ @article{ryali2023hiera,
137
+ title={Hiera: A Hierarchical Vision Transformer without the Bells-and-Whistles},
138
+ author={Ryali, Chaitanya and Hu, Yuan-Ting and Bolya, Daniel and Wei, Chen and Fan, Haoqi and Huang, Po-Yao and Aggarwal, Vaibhav and Chowdhury, Arkabandhu and Poursaeed, Omid and Hoffman, Judy and Malik, Jitendra and Li, Yanghao and Feichtenhofer, Christoph},
139
+ journal={ICML},
140
+ year={2023}
141
+ }
142
+ ```
143
+ ```bibtex
144
+ @misc{rw2019timm,
145
+ author = {Ross Wightman},
146
+ title = {PyTorch Image Models},
147
+ year = {2019},
148
+ publisher = {GitHub},
149
+ journal = {GitHub repository},
150
+ doi = {10.5281/zenodo.4414861},
151
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
152
+ }
153
+ ```
154
+ ```bibtex
155
+ @article{bolya2023window,
156
+ title={Window Attention is Bugged: How not to Interpolate Position Embeddings},
157
+ author={Bolya, Daniel and Ryali, Chaitanya and Hoffman, Judy and Feichtenhofer, Christoph},
158
+ journal={arXiv preprint arXiv:2311.05613},
159
+ year={2023}
160
+ }
161
+ ```
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "hiera_small_abswin_256",
3
+ "num_classes": 1000,
4
+ "num_features": 768,
5
+ "pretrained_cfg": {
6
+ "tag": "sbb2_pd_e200_in12k_ft_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 256,
11
+ 256
12
+ ],
13
+ "fixed_input_size": true,
14
+ "interpolation": "bicubic",
15
+ "crop_pct": 0.95,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.485,
19
+ 0.456,
20
+ 0.406
21
+ ],
22
+ "std": [
23
+ 0.229,
24
+ 0.224,
25
+ 0.225
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": null,
29
+ "first_conv": "patch_embed.proj",
30
+ "classifier": "head.fc"
31
+ }
32
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d82f840b21e1c89dbfba397ef4010239ddc2644ca23f7fab6df18e41420d50c
3
+ size 137468288
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:00ffd5f1ac9f4380ae8f906e1dc14c6ed8cfb123bcb9b021ba59d77f53a51b1d
3
+ size 137528301