Add model
Browse files- README.md +159 -0
- config.json +35 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
library_tag: timm
|
6 |
+
license: apache-2.0
|
7 |
+
---
|
8 |
+
# Model card for cspresnet50.ra_in1k
|
9 |
+
|
10 |
+
A CSP-ResNet (Cross-Stage-Partial) image classification model. Trained on ImageNet-1k in `timm` using recipe template described below.
|
11 |
+
|
12 |
+
Recipe details:
|
13 |
+
* RandAugment `RA` recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as `B` recipe in [ResNet Strikes Back](https://arxiv.org/abs/2110.00476).
|
14 |
+
* RMSProp (TF 1.0 behaviour) optimizer, EMA weight averaging
|
15 |
+
* Step (exponential decay w/ staircase) LR schedule with warmup
|
16 |
+
|
17 |
+
|
18 |
+
## Model Details
|
19 |
+
- **Model Type:** Image classification / feature backbone
|
20 |
+
- **Model Stats:**
|
21 |
+
- Params (M): 21.6
|
22 |
+
- GMACs: 4.5
|
23 |
+
- Activations (M): 11.5
|
24 |
+
- Image size: 256 x 256
|
25 |
+
- **Papers:**
|
26 |
+
- CSPNet: A New Backbone that can Enhance Learning Capability of CNN: https://arxiv.org/abs/1911.11929
|
27 |
+
- Deep Residual Learning for Image Recognition: https://arxiv.org/abs/1512.03385
|
28 |
+
- ResNet strikes back: An improved training procedure in timm: https://arxiv.org/abs/2110.00476
|
29 |
+
- **Original:** https://github.com/huggingface/pytorch-image-models
|
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('cspresnet50.ra_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 |
+
'cspresnet50.ra_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, 64, 128, 128])
|
81 |
+
# torch.Size([1, 128, 64, 64])
|
82 |
+
# torch.Size([1, 256, 32, 32])
|
83 |
+
# torch.Size([1, 512, 16, 16])
|
84 |
+
# torch.Size([1, 1024, 8, 8])
|
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 |
+
'cspresnet50.ra_in1k',
|
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, 1024, 8, 8) 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 |
+
@article{Wang2019CSPNetAN,
|
127 |
+
title={CSPNet: A New Backbone that can Enhance Learning Capability of CNN},
|
128 |
+
author={Chien-Yao Wang and Hong-Yuan Mark Liao and I-Hau Yeh and Yueh-Hua Wu and Ping-Yang Chen and Jun-Wei Hsieh},
|
129 |
+
journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
|
130 |
+
year={2019},
|
131 |
+
pages={1571-1580}
|
132 |
+
}
|
133 |
+
```
|
134 |
+
```bibtex
|
135 |
+
@article{He2015,
|
136 |
+
author = {Kaiming He and Xiangyu Zhang and Shaoqing Ren and Jian Sun},
|
137 |
+
title = {Deep Residual Learning for Image Recognition},
|
138 |
+
journal = {arXiv preprint arXiv:1512.03385},
|
139 |
+
year = {2015}
|
140 |
+
}
|
141 |
+
```
|
142 |
+
```bibtex
|
143 |
+
@inproceedings{wightman2021resnet,
|
144 |
+
title={ResNet strikes back: An improved training procedure in timm},
|
145 |
+
author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
|
146 |
+
booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
|
147 |
+
}
|
148 |
+
```
|
149 |
+
```bibtex
|
150 |
+
@misc{rw2019timm,
|
151 |
+
author = {Ross Wightman},
|
152 |
+
title = {PyTorch Image Models},
|
153 |
+
year = {2019},
|
154 |
+
publisher = {GitHub},
|
155 |
+
journal = {GitHub repository},
|
156 |
+
doi = {10.5281/zenodo.4414861},
|
157 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
158 |
+
}
|
159 |
+
```
|
config.json
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "cspresnet50",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 1024,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "ra_in1k",
|
7 |
+
"custom_load": false,
|
8 |
+
"input_size": [
|
9 |
+
3,
|
10 |
+
256,
|
11 |
+
256
|
12 |
+
],
|
13 |
+
"fixed_input_size": false,
|
14 |
+
"interpolation": "bilinear",
|
15 |
+
"crop_pct": 0.887,
|
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": [
|
29 |
+
8,
|
30 |
+
8
|
31 |
+
],
|
32 |
+
"first_conv": "stem.conv1.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:f34ed53e4bb92e01538a2265c5d503db0bcfe149be6fc1ae21d3be842af2cea8
|
3 |
+
size 86660410
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f29e438fc7f5d3063ac66915d8528b3438345078008d8943c2fe3c88c2253cb1
|
3 |
+
size 86748285
|