timm
/

Image Classification
timm
PyTorch
Safetensors
rwightman HF staff commited on
Commit
2281885
1 Parent(s): a6ee04d
Files changed (4) hide show
  1. README.md +170 -0
  2. config.json +40 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
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 haloregnetz_b.ra3_in1k
11
+
12
+ A HaloNet image classification model (, based on RegNet-Z architecture). Trained on ImageNet-1k in `timm` by Ross Wightman.
13
+
14
+ NOTE: this model did not adhere to any specific paper configuration, it was tuned for reasonable training times and reduced frequency of self-attention blocks.
15
+
16
+ Recipe details:
17
+ * RandAugment `RA3` recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
18
+ * RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
19
+ * Step (exponential decay w/ staircase) LR schedule with warmup
20
+
21
+ This model architecture is implemented using `timm`'s flexible [BYOBNet (Bring-Your-Own-Blocks Network)](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/byobnet.py).
22
+
23
+ BYOB (with BYOANet attention specific blocks) allows configuration of:
24
+ * block / stage layout
25
+ * block-type interleaving
26
+ * stem layout
27
+ * output stride (dilation)
28
+ * activation and norm layers
29
+ * channel and spatial / self-attention layers
30
+
31
+ ...and also includes `timm` features common to many other architectures, including:
32
+ * stochastic depth
33
+ * gradient checkpointing
34
+ * layer-wise LR decay
35
+ * per-stage feature extraction
36
+
37
+
38
+ ## Model Details
39
+ - **Model Type:** Image classification / feature backbone
40
+ - **Model Stats:**
41
+ - Params (M): 11.7
42
+ - GMACs: 2.0
43
+ - Activations (M): 11.9
44
+ - Image size: 224 x 224
45
+ - **Papers:**
46
+ - Scaling Local Self-Attention for Parameter Efficient Visual Backbones: https://arxiv.org/abs/2103.12731
47
+ - ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
48
+ - **Dataset:** ImageNet-1k
49
+
50
+ ## Model Usage
51
+ ### Image Classification
52
+ ```python
53
+ from urllib.request import urlopen
54
+ from PIL import Image
55
+ import timm
56
+
57
+ img = Image.open(urlopen(
58
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
59
+ ))
60
+
61
+ model = timm.create_model('haloregnetz_b.ra3_in1k', pretrained=True)
62
+ model = model.eval()
63
+
64
+ # get model specific transforms (normalization, resize)
65
+ data_config = timm.data.resolve_model_data_config(model)
66
+ transforms = timm.data.create_transform(**data_config, is_training=False)
67
+
68
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
69
+
70
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
71
+ ```
72
+
73
+ ### Feature Map Extraction
74
+ ```python
75
+ from urllib.request import urlopen
76
+ from PIL import Image
77
+ import timm
78
+
79
+ img = Image.open(urlopen(
80
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
81
+ ))
82
+
83
+ model = timm.create_model(
84
+ 'haloregnetz_b.ra3_in1k',
85
+ pretrained=True,
86
+ features_only=True,
87
+ )
88
+ model = model.eval()
89
+
90
+ # get model specific transforms (normalization, resize)
91
+ data_config = timm.data.resolve_model_data_config(model)
92
+ transforms = timm.data.create_transform(**data_config, is_training=False)
93
+
94
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
95
+
96
+ for o in output:
97
+ # print shape of each feature map in output
98
+ # e.g.:
99
+ # torch.Size([1, 32, 112, 112])
100
+ # torch.Size([1, 48, 56, 56])
101
+ # torch.Size([1, 96, 28, 28])
102
+ # torch.Size([1, 192, 14, 14])
103
+ # torch.Size([1, 1536, 7, 7])
104
+
105
+ print(o.shape)
106
+ ```
107
+
108
+ ### Image Embeddings
109
+ ```python
110
+ from urllib.request import urlopen
111
+ from PIL import Image
112
+ import timm
113
+
114
+ img = Image.open(urlopen(
115
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
116
+ ))
117
+
118
+ model = timm.create_model(
119
+ 'haloregnetz_b.ra3_in1k',
120
+ pretrained=True,
121
+ num_classes=0, # remove classifier nn.Linear
122
+ )
123
+ model = model.eval()
124
+
125
+ # get model specific transforms (normalization, resize)
126
+ data_config = timm.data.resolve_model_data_config(model)
127
+ transforms = timm.data.create_transform(**data_config, is_training=False)
128
+
129
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
130
+
131
+ # or equivalently (without needing to set num_classes=0)
132
+
133
+ output = model.forward_features(transforms(img).unsqueeze(0))
134
+ # output is unpooled, a (1, 1536, 7, 7) shaped tensor
135
+
136
+ output = model.forward_head(output, pre_logits=True)
137
+ # output is a (1, num_features) shaped tensor
138
+ ```
139
+
140
+ ## Model Comparison
141
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
142
+
143
+ ## Citation
144
+ ```bibtex
145
+ @misc{rw2019timm,
146
+ author = {Ross Wightman},
147
+ title = {PyTorch Image Models},
148
+ year = {2019},
149
+ publisher = {GitHub},
150
+ journal = {GitHub repository},
151
+ doi = {10.5281/zenodo.4414861},
152
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
153
+ }
154
+ ```
155
+ ```bibtex
156
+ @article{Vaswani2021ScalingLS,
157
+ title={Scaling Local Self-Attention for Parameter Efficient Visual Backbones},
158
+ author={Ashish Vaswani and Prajit Ramachandran and A. Srinivas and Niki Parmar and Blake A. Hechtman and Jonathon Shlens},
159
+ journal={2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
160
+ year={2021},
161
+ pages={12889-12899}
162
+ }
163
+ ```
164
+ ```bibtex
165
+ @inproceedings{wightman2021resnet,
166
+ title={ResNet strikes back: An improved training procedure in timm},
167
+ author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
168
+ booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
169
+ }
170
+ ```
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "haloregnetz_b",
3
+ "num_classes": 1000,
4
+ "num_features": 1536,
5
+ "pretrained_cfg": {
6
+ "tag": "ra3_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 224,
11
+ 224
12
+ ],
13
+ "min_input_size": [
14
+ 3,
15
+ 224,
16
+ 224
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.94,
21
+ "crop_mode": "center",
22
+ "mean": [
23
+ 0.5,
24
+ 0.5,
25
+ 0.5
26
+ ],
27
+ "std": [
28
+ 0.5,
29
+ 0.5,
30
+ 0.5
31
+ ],
32
+ "num_classes": 1000,
33
+ "pool_size": [
34
+ 7,
35
+ 7
36
+ ],
37
+ "first_conv": "stem.conv",
38
+ "classifier": "head.fc"
39
+ }
40
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1b95e193231ac496b95e61e923f2f5feef49d9ee773bc8b83dc93ee1680cdd1
3
+ size 46969098
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f8a230dd279977c90d5a5d3527a851aa085beb1985f182cdef274d412269250
3
+ size 47099777