timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
96b8566
1 Parent(s): 26c8f59
Files changed (4) hide show
  1. README.md +153 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ - imagenet-21k
10
+ ---
11
+ # Model card for resnetv2_101x3_bit.goog_in21k_ft_in1k
12
+
13
+ A ResNet-V2-BiT (Big Transfer w/ pre-activation ResNet) image classification model. Pretrained on ImageNet-21k and fine-tuned on ImageNet-1k by paper authors.
14
+
15
+ This model uses:
16
+ * Group Normalization (GN) in combination with Weight Standardization (WS) instead of Batch Normalization (BN)..
17
+
18
+
19
+ ## Model Details
20
+ - **Model Type:** Image classification / feature backbone
21
+ - **Model Stats:**
22
+ - Params (M): 387.9
23
+ - GMACs: 280.3
24
+ - Activations (M): 194.8
25
+ - Image size: 448 x 448
26
+ - **Papers:**
27
+ - Big Transfer (BiT): General Visual Representation Learning: https://arxiv.org/abs/1912.11370
28
+ - Identity Mappings in Deep Residual Networks: https://arxiv.org/abs/1603.05027
29
+ - **Dataset:** ImageNet-1k
30
+ - **Pretrain Dataset:** ImageNet-21k
31
+ - **Original:** https://github.com/google-research/big_transfer
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('resnetv2_101x3_bit.goog_in21k_ft_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
+ ### Feature Map Extraction
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
+ 'resnetv2_101x3_bit.goog_in21k_ft_in1k',
68
+ pretrained=True,
69
+ features_only=True,
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)) # unsqueeze single image into batch of 1
78
+
79
+ for o in output:
80
+ # print shape of each feature map in output
81
+ # e.g.:
82
+ # torch.Size([1, 192, 224, 224])
83
+ # torch.Size([1, 768, 112, 112])
84
+ # torch.Size([1, 1536, 56, 56])
85
+ # torch.Size([1, 3072, 28, 28])
86
+ # torch.Size([1, 6144, 14, 14])
87
+
88
+ print(o.shape)
89
+ ```
90
+
91
+ ### Image Embeddings
92
+ ```python
93
+ from urllib.request import urlopen
94
+ from PIL import Image
95
+ import timm
96
+
97
+ img = Image.open(urlopen(
98
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
99
+ ))
100
+
101
+ model = timm.create_model(
102
+ 'resnetv2_101x3_bit.goog_in21k_ft_in1k',
103
+ pretrained=True,
104
+ num_classes=0, # remove classifier nn.Linear
105
+ )
106
+ model = model.eval()
107
+
108
+ # get model specific transforms (normalization, resize)
109
+ data_config = timm.data.resolve_model_data_config(model)
110
+ transforms = timm.data.create_transform(**data_config, is_training=False)
111
+
112
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
113
+
114
+ # or equivalently (without needing to set num_classes=0)
115
+
116
+ output = model.forward_features(transforms(img).unsqueeze(0))
117
+ # output is unpooled, a (1, 6144, 14, 14) shaped tensor
118
+
119
+ output = model.forward_head(output, pre_logits=True)
120
+ # output is a (1, num_features) shaped tensor
121
+ ```
122
+
123
+ ## Model Comparison
124
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
125
+
126
+ ## Citation
127
+ ```bibtex
128
+ @inproceedings{Kolesnikov2019BigT,
129
+ title={Big Transfer (BiT): General Visual Representation Learning},
130
+ author={Alexander Kolesnikov and Lucas Beyer and Xiaohua Zhai and Joan Puigcerver and Jessica Yung and Sylvain Gelly and Neil Houlsby},
131
+ booktitle={European Conference on Computer Vision},
132
+ year={2019}
133
+ }
134
+ ```
135
+ ```bibtex
136
+ @article{He2016,
137
+ author = {Kaiming He and Xiangyu Zhang and Shaoqing Ren and Jian Sun},
138
+ title = {Identity Mappings in Deep Residual Networks},
139
+ journal = {arXiv preprint arXiv:1603.05027},
140
+ year = {2016}
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
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "resnetv2_101x3_bit",
3
+ "num_classes": 1000,
4
+ "num_features": 6144,
5
+ "pretrained_cfg": {
6
+ "tag": "goog_in21k_ft_in1k",
7
+ "custom_load": true,
8
+ "input_size": [
9
+ 3,
10
+ 448,
11
+ 448
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bilinear",
15
+ "crop_pct": 1.0,
16
+ "crop_mode": "center",
17
+ "mean": [
18
+ 0.5,
19
+ 0.5,
20
+ 0.5
21
+ ],
22
+ "std": [
23
+ 0.5,
24
+ 0.5,
25
+ 0.5
26
+ ],
27
+ "num_classes": 1000,
28
+ "pool_size": [
29
+ 14,
30
+ 14
31
+ ],
32
+ "first_conv": "stem.conv",
33
+ "classifier": "head.fc"
34
+ }
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d1ef6077f749e7f7a8e6b23acd35175acd156ad1c67931b2e7fbb06eef8e4d9
3
+ size 1551770940
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5ff127a5a4750092a1f3b7ba93e293d02bf14e72c0014db287e13535b89720c
3
+ size 1551859925