Add model
Browse files- README.md +171 -0
- config.json +40 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 sebotnet33ts_256.a1h_in1k
|
11 |
+
|
12 |
+
A BotNet image classification model (with Squeeze-and-Excitation channel attention, based on ResNet 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 |
+
* Based on [ResNet Strikes Back](https://arxiv.org/abs/2110.00476) `A1` recipe
|
18 |
+
* LAMB optimizer
|
19 |
+
* Stronger dropout, stochastic depth, and RandAugment than paper `A1` recipe
|
20 |
+
* Cosine LR schedule with warmup
|
21 |
+
|
22 |
+
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).
|
23 |
+
|
24 |
+
BYOB (with BYOANet attention specific blocks) allows configuration of:
|
25 |
+
* block / stage layout
|
26 |
+
* block-type interleaving
|
27 |
+
* stem layout
|
28 |
+
* output stride (dilation)
|
29 |
+
* activation and norm layers
|
30 |
+
* channel and spatial / self-attention layers
|
31 |
+
|
32 |
+
...and also includes `timm` features common to many other architectures, including:
|
33 |
+
* stochastic depth
|
34 |
+
* gradient checkpointing
|
35 |
+
* layer-wise LR decay
|
36 |
+
* per-stage feature extraction
|
37 |
+
|
38 |
+
|
39 |
+
## Model Details
|
40 |
+
- **Model Type:** Image classification / feature backbone
|
41 |
+
- **Model Stats:**
|
42 |
+
- Params (M): 13.7
|
43 |
+
- GMACs: 3.9
|
44 |
+
- Activations (M): 17.5
|
45 |
+
- Image size: 256 x 256
|
46 |
+
- **Papers:**
|
47 |
+
- Bottleneck Transformers for Visual Recognition: https://arxiv.org/abs/2101.11605
|
48 |
+
- ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
|
49 |
+
- **Dataset:** ImageNet-1k
|
50 |
+
|
51 |
+
## Model Usage
|
52 |
+
### Image Classification
|
53 |
+
```python
|
54 |
+
from urllib.request import urlopen
|
55 |
+
from PIL import Image
|
56 |
+
import timm
|
57 |
+
|
58 |
+
img = Image.open(urlopen(
|
59 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
60 |
+
))
|
61 |
+
|
62 |
+
model = timm.create_model('sebotnet33ts_256.a1h_in1k', pretrained=True)
|
63 |
+
model = model.eval()
|
64 |
+
|
65 |
+
# get model specific transforms (normalization, resize)
|
66 |
+
data_config = timm.data.resolve_model_data_config(model)
|
67 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
68 |
+
|
69 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
70 |
+
|
71 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
72 |
+
```
|
73 |
+
|
74 |
+
### Feature Map Extraction
|
75 |
+
```python
|
76 |
+
from urllib.request import urlopen
|
77 |
+
from PIL import Image
|
78 |
+
import timm
|
79 |
+
|
80 |
+
img = Image.open(urlopen(
|
81 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
82 |
+
))
|
83 |
+
|
84 |
+
model = timm.create_model(
|
85 |
+
'sebotnet33ts_256.a1h_in1k',
|
86 |
+
pretrained=True,
|
87 |
+
features_only=True,
|
88 |
+
)
|
89 |
+
model = model.eval()
|
90 |
+
|
91 |
+
# get model specific transforms (normalization, resize)
|
92 |
+
data_config = timm.data.resolve_model_data_config(model)
|
93 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
94 |
+
|
95 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
96 |
+
|
97 |
+
for o in output:
|
98 |
+
# print shape of each feature map in output
|
99 |
+
# e.g.:
|
100 |
+
# torch.Size([1, 32, 128, 128])
|
101 |
+
# torch.Size([1, 256, 64, 64])
|
102 |
+
# torch.Size([1, 512, 32, 32])
|
103 |
+
# torch.Size([1, 1024, 16, 16])
|
104 |
+
# torch.Size([1, 1280, 8, 8])
|
105 |
+
|
106 |
+
print(o.shape)
|
107 |
+
```
|
108 |
+
|
109 |
+
### Image Embeddings
|
110 |
+
```python
|
111 |
+
from urllib.request import urlopen
|
112 |
+
from PIL import Image
|
113 |
+
import timm
|
114 |
+
|
115 |
+
img = Image.open(urlopen(
|
116 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
117 |
+
))
|
118 |
+
|
119 |
+
model = timm.create_model(
|
120 |
+
'sebotnet33ts_256.a1h_in1k',
|
121 |
+
pretrained=True,
|
122 |
+
num_classes=0, # remove classifier nn.Linear
|
123 |
+
)
|
124 |
+
model = model.eval()
|
125 |
+
|
126 |
+
# get model specific transforms (normalization, resize)
|
127 |
+
data_config = timm.data.resolve_model_data_config(model)
|
128 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
129 |
+
|
130 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
131 |
+
|
132 |
+
# or equivalently (without needing to set num_classes=0)
|
133 |
+
|
134 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
135 |
+
# output is unpooled, a (1, 1280, 8, 8) shaped tensor
|
136 |
+
|
137 |
+
output = model.forward_head(output, pre_logits=True)
|
138 |
+
# output is a (1, num_features) shaped tensor
|
139 |
+
```
|
140 |
+
|
141 |
+
## Model Comparison
|
142 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
143 |
+
|
144 |
+
## Citation
|
145 |
+
```bibtex
|
146 |
+
@misc{rw2019timm,
|
147 |
+
author = {Ross Wightman},
|
148 |
+
title = {PyTorch Image Models},
|
149 |
+
year = {2019},
|
150 |
+
publisher = {GitHub},
|
151 |
+
journal = {GitHub repository},
|
152 |
+
doi = {10.5281/zenodo.4414861},
|
153 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
154 |
+
}
|
155 |
+
```
|
156 |
+
```bibtex
|
157 |
+
@article{Srinivas2021BottleneckTF,
|
158 |
+
title={Bottleneck Transformers for Visual Recognition},
|
159 |
+
author={A. Srinivas and Tsung-Yi Lin and Niki Parmar and Jonathon Shlens and P. Abbeel and Ashish Vaswani},
|
160 |
+
journal={2021 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
161 |
+
year={2021},
|
162 |
+
pages={16514-16524}
|
163 |
+
}
|
164 |
+
```
|
165 |
+
```bibtex
|
166 |
+
@inproceedings{wightman2021resnet,
|
167 |
+
title={ResNet strikes back: An improved training procedure in timm},
|
168 |
+
author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
|
169 |
+
booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
|
170 |
+
}
|
171 |
+
```
|
config.json
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "sebotnet33ts_256",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 1280,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "a1h_in1k",
|
7 |
+
"custom_load": false,
|
8 |
+
"input_size": [
|
9 |
+
3,
|
10 |
+
256,
|
11 |
+
256
|
12 |
+
],
|
13 |
+
"min_input_size": [
|
14 |
+
3,
|
15 |
+
224,
|
16 |
+
224
|
17 |
+
],
|
18 |
+
"fixed_input_size": true,
|
19 |
+
"interpolation": "bicubic",
|
20 |
+
"crop_pct": 0.94,
|
21 |
+
"crop_mode": "center",
|
22 |
+
"mean": [
|
23 |
+
0.485,
|
24 |
+
0.456,
|
25 |
+
0.406
|
26 |
+
],
|
27 |
+
"std": [
|
28 |
+
0.229,
|
29 |
+
0.224,
|
30 |
+
0.225
|
31 |
+
],
|
32 |
+
"num_classes": 1000,
|
33 |
+
"pool_size": [
|
34 |
+
8,
|
35 |
+
8
|
36 |
+
],
|
37 |
+
"first_conv": "stem.conv1.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:f4e3af372c615699a90721d2f4ea89568e12dc9f12230976c6f8ea5f028455be
|
3 |
+
size 54974504
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:42205c36b07b5d8a9693b585a4f31ec5803692bd808256807b8242db7617712b
|
3 |
+
size 55042789
|