Add model
Browse files- README.md +153 -0
- config.json +41 -0
- model.safetensors +3 -0
- 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-12k
|
10 |
+
---
|
11 |
+
# Model card for rexnetr_200.sw_in12k_ft_in1k
|
12 |
+
|
13 |
+
A ReXNet-R image classification model. The R variant of the architecture is `timm` specific and rounds channels (modulus 8 or 16) to prevent performance issues w/ NVIDIA Tensor Cores. Pretrained on ImageNet-12k and fine-tuned on ImageNet-1k by Ross Wightman in `timm`.
|
14 |
+
|
15 |
+
|
16 |
+
## Model Details
|
17 |
+
- **Model Type:** Image classification / feature backbone
|
18 |
+
- **Model Stats:**
|
19 |
+
- Params (M): 16.5
|
20 |
+
- GMACs: 1.6
|
21 |
+
- Activations (M): 15.1
|
22 |
+
- Image size: train = 224 x 224, test = 288 x 288
|
23 |
+
- **Papers:**
|
24 |
+
- Rethinking Channel Dimensions for Efficient Model Design: https://arxiv.org/abs/2007.00992
|
25 |
+
- **Original:** https://github.com/huggingface/pytorch-image-models
|
26 |
+
- **Dataset:** ImageNet-1k
|
27 |
+
- **Pretrain Dataset:** ImageNet-12k
|
28 |
+
|
29 |
+
## Model Usage
|
30 |
+
### Image Classification
|
31 |
+
```python
|
32 |
+
from urllib.request import urlopen
|
33 |
+
from PIL import Image
|
34 |
+
import timm
|
35 |
+
|
36 |
+
img = Image.open(urlopen(
|
37 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
38 |
+
))
|
39 |
+
|
40 |
+
model = timm.create_model('rexnetr_200.sw_in12k_ft_in1k', pretrained=True)
|
41 |
+
model = model.eval()
|
42 |
+
|
43 |
+
# get model specific transforms (normalization, resize)
|
44 |
+
data_config = timm.data.resolve_model_data_config(model)
|
45 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
46 |
+
|
47 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
48 |
+
|
49 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
50 |
+
```
|
51 |
+
|
52 |
+
### Feature Map Extraction
|
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(
|
63 |
+
'rexnetr_200.sw_in12k_ft_in1k',
|
64 |
+
pretrained=True,
|
65 |
+
features_only=True,
|
66 |
+
)
|
67 |
+
model = model.eval()
|
68 |
+
|
69 |
+
# get model specific transforms (normalization, resize)
|
70 |
+
data_config = timm.data.resolve_model_data_config(model)
|
71 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
72 |
+
|
73 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
74 |
+
|
75 |
+
for o in output:
|
76 |
+
# print shape of each feature map in output
|
77 |
+
# e.g.:
|
78 |
+
# torch.Size([1, 32, 112, 112])
|
79 |
+
# torch.Size([1, 80, 56, 56])
|
80 |
+
# torch.Size([1, 120, 28, 28])
|
81 |
+
# torch.Size([1, 256, 14, 14])
|
82 |
+
# torch.Size([1, 368, 7, 7])
|
83 |
+
|
84 |
+
print(o.shape)
|
85 |
+
```
|
86 |
+
|
87 |
+
### Image Embeddings
|
88 |
+
```python
|
89 |
+
from urllib.request import urlopen
|
90 |
+
from PIL import Image
|
91 |
+
import timm
|
92 |
+
|
93 |
+
img = Image.open(urlopen(
|
94 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
95 |
+
))
|
96 |
+
|
97 |
+
model = timm.create_model(
|
98 |
+
'rexnetr_200.sw_in12k_ft_in1k',
|
99 |
+
pretrained=True,
|
100 |
+
num_classes=0, # remove classifier nn.Linear
|
101 |
+
)
|
102 |
+
model = model.eval()
|
103 |
+
|
104 |
+
# get model specific transforms (normalization, resize)
|
105 |
+
data_config = timm.data.resolve_model_data_config(model)
|
106 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
107 |
+
|
108 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
109 |
+
|
110 |
+
# or equivalently (without needing to set num_classes=0)
|
111 |
+
|
112 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
113 |
+
# output is unpooled, a (1, 2560, 7, 7) shaped tensor
|
114 |
+
|
115 |
+
output = model.forward_head(output, pre_logits=True)
|
116 |
+
# output is a (1, num_features) shaped tensor
|
117 |
+
```
|
118 |
+
|
119 |
+
## Model Comparison
|
120 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results)."
|
121 |
+
|
122 |
+
|model |top1 |top5 |param_count|img_size|crop_pct|
|
123 |
+
|-------------------------|------|------|-----------|--------|--------|
|
124 |
+
|rexnetr_300.sw_in12k_ft_in1k|84.53 |97.252|34.81 |288 |1.0 |
|
125 |
+
|rexnetr_200.sw_in12k_ft_in1k|83.164|96.648|16.52 |288 |1.0 |
|
126 |
+
|rexnet_300.nav_in1k |82.772|96.232|34.71 |224 |0.875 |
|
127 |
+
|rexnet_200.nav_in1k |81.652|95.668|16.37 |224 |0.875 |
|
128 |
+
|rexnet_150.nav_in1k |80.308|95.174|9.73 |224 |0.875 |
|
129 |
+
|rexnet_130.nav_in1k |79.478|94.68 |7.56 |224 |0.875 |
|
130 |
+
|rexnet_100.nav_in1k |77.832|93.886|4.8 |224 |0.875 |
|
131 |
+
|
132 |
+
## Citation
|
133 |
+
```bibtex
|
134 |
+
@misc{han2021rethinking,
|
135 |
+
title={Rethinking Channel Dimensions for Efficient Model Design},
|
136 |
+
author={Dongyoon Han and Sangdoo Yun and Byeongho Heo and YoungJoon Yoo},
|
137 |
+
year={2021},
|
138 |
+
eprint={2007.00992},
|
139 |
+
archivePrefix={arXiv},
|
140 |
+
primaryClass={cs.CV}
|
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,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "rexnetr_200",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 2560,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "sw_in12k_ft_in1k",
|
7 |
+
"custom_load": false,
|
8 |
+
"input_size": [
|
9 |
+
3,
|
10 |
+
224,
|
11 |
+
224
|
12 |
+
],
|
13 |
+
"test_input_size": [
|
14 |
+
3,
|
15 |
+
288,
|
16 |
+
288
|
17 |
+
],
|
18 |
+
"fixed_input_size": false,
|
19 |
+
"interpolation": "bicubic",
|
20 |
+
"crop_pct": 1.0,
|
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 |
+
7,
|
35 |
+
7
|
36 |
+
],
|
37 |
+
"first_conv": "stem.conv",
|
38 |
+
"classifier": "head.fc",
|
39 |
+
"license": "apache-2.0"
|
40 |
+
}
|
41 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d92c098c499b8482bc824bec5c4c79acb47d82c54aa48285e5b3c39118f3e8fc
|
3 |
+
size 66463248
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:71c5a18d39c0bbeeca2c4e7777a83b9e6fa43ee7d966599b81930322c706d694
|
3 |
+
size 66564353
|