timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
9c19834
1 Parent(s): ed5d463
Files changed (4) hide show
  1. README.md +151 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-21k
9
+ ---
10
+ # Model card for resnetv2_50x1_bit.goog_in21k
11
+
12
+ A ResNet-V2-BiT (Big Transfer w/ pre-activation ResNet) image classification model. Trained on ImageNet-21k by paper authors.
13
+
14
+ This model uses:
15
+ * Group Normalization (GN) in combination with Weight Standardization (WS) instead of Batch Normalization (BN)..
16
+
17
+
18
+ ## Model Details
19
+ - **Model Type:** Image classification / feature backbone
20
+ - **Model Stats:**
21
+ - Params (M): 68.3
22
+ - GMACs: 4.3
23
+ - Activations (M): 11.1
24
+ - Image size: 224 x 224
25
+ - **Papers:**
26
+ - Big Transfer (BiT): General Visual Representation Learning: https://arxiv.org/abs/1912.11370
27
+ - Identity Mappings in Deep Residual Networks: https://arxiv.org/abs/1603.05027
28
+ - **Dataset:** ImageNet-21k
29
+ - **Original:** https://github.com/google-research/big_transfer
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('resnetv2_50x1_bit.goog_in21k', 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
+ 'resnetv2_50x1_bit.goog_in21k',
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, 64, 112, 112])
81
+ # torch.Size([1, 256, 56, 56])
82
+ # torch.Size([1, 512, 28, 28])
83
+ # torch.Size([1, 1024, 14, 14])
84
+ # torch.Size([1, 2048, 7, 7])
85
+
86
+ print(o.shape)
87
+ ```
88
+
89
+ ### Image Embeddings
90
+ ```python
91
+ from urllib.request import urlopen
92
+ from PIL import Image
93
+ import timm
94
+
95
+ img = Image.open(urlopen(
96
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
97
+ ))
98
+
99
+ model = timm.create_model(
100
+ 'resnetv2_50x1_bit.goog_in21k',
101
+ pretrained=True,
102
+ num_classes=0, # remove classifier nn.Linear
103
+ )
104
+ model = model.eval()
105
+
106
+ # get model specific transforms (normalization, resize)
107
+ data_config = timm.data.resolve_model_data_config(model)
108
+ transforms = timm.data.create_transform(**data_config, is_training=False)
109
+
110
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
111
+
112
+ # or equivalently (without needing to set num_classes=0)
113
+
114
+ output = model.forward_features(transforms(img).unsqueeze(0))
115
+ # output is unpooled, a (1, 2048, 7, 7) shaped tensor
116
+
117
+ output = model.forward_head(output, pre_logits=True)
118
+ # output is a (1, num_features) shaped tensor
119
+ ```
120
+
121
+ ## Model Comparison
122
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
123
+
124
+ ## Citation
125
+ ```bibtex
126
+ @inproceedings{Kolesnikov2019BigT,
127
+ title={Big Transfer (BiT): General Visual Representation Learning},
128
+ author={Alexander Kolesnikov and Lucas Beyer and Xiaohua Zhai and Joan Puigcerver and Jessica Yung and Sylvain Gelly and Neil Houlsby},
129
+ booktitle={European Conference on Computer Vision},
130
+ year={2019}
131
+ }
132
+ ```
133
+ ```bibtex
134
+ @article{He2016,
135
+ author = {Kaiming He and Xiangyu Zhang and Shaoqing Ren and Jian Sun},
136
+ title = {Identity Mappings in Deep Residual Networks},
137
+ journal = {arXiv preprint arXiv:1603.05027},
138
+ year = {2016}
139
+ }
140
+ ```
141
+ ```bibtex
142
+ @misc{rw2019timm,
143
+ author = {Ross Wightman},
144
+ title = {PyTorch Image Models},
145
+ year = {2019},
146
+ publisher = {GitHub},
147
+ journal = {GitHub repository},
148
+ doi = {10.5281/zenodo.4414861},
149
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
150
+ }
151
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "resnetv2_50x1_bit",
3
+ "num_classes": 21843,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "goog_in21k",
7
+ "custom_load": true,
8
+ "input_size": [
9
+ 3,
10
+ 224,
11
+ 224
12
+ ],
13
+ "fixed_input_size": false,
14
+ "interpolation": "bilinear",
15
+ "crop_pct": 0.875,
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": 21843,
28
+ "pool_size": [
29
+ 7,
30
+ 7
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:a619aed743e00eaf0ca3421ba53e8322ea3ae942fca8cfbd6b155285f30666bb
3
+ size 273042230
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae0874dc31faeeb320c0a1e0f59a71b767006a6911934ad1792c1df30a5ece68
3
+ size 273086769