Add model
Browse files- README.md +156 -0
- config.json +35 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
library_tag: timm
|
6 |
+
license: apache-2.0
|
7 |
+
datasets:
|
8 |
+
- imagenet-1k
|
9 |
+
---
|
10 |
+
# Model card for gernet_m.idstcv_in1k
|
11 |
+
|
12 |
+
A GENet (GPU-Efficient-Networks) image classification model. Trained on ImageNet-1k by paper authors.
|
13 |
+
|
14 |
+
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).
|
15 |
+
|
16 |
+
BYOBNet allows configuration of:
|
17 |
+
* block / stage layout
|
18 |
+
* stem layout
|
19 |
+
* output stride (dilation)
|
20 |
+
* activation and norm layers
|
21 |
+
* channel and spatial / self-attention layers
|
22 |
+
|
23 |
+
...and also includes `timm` features common to many other architectures, including:
|
24 |
+
* stochastic depth
|
25 |
+
* gradient checkpointing
|
26 |
+
* layer-wise LR decay
|
27 |
+
* per-stage feature extraction
|
28 |
+
|
29 |
+
|
30 |
+
## Model Details
|
31 |
+
- **Model Type:** Image classification / feature backbone
|
32 |
+
- **Model Stats:**
|
33 |
+
- Params (M): 21.1
|
34 |
+
- GMACs: 3.0
|
35 |
+
- Activations (M): 5.2
|
36 |
+
- Image size: 224 x 224
|
37 |
+
- **Papers:**
|
38 |
+
- Neural Architecture Design for GPU-Efficient Networks: https://arxiv.org/abs/2006.14090
|
39 |
+
- **Dataset:** ImageNet-1k
|
40 |
+
- **Original:** https://github.com/idstcv/GPU-Efficient-Networks
|
41 |
+
|
42 |
+
## Model Usage
|
43 |
+
### Image Classification
|
44 |
+
```python
|
45 |
+
from urllib.request import urlopen
|
46 |
+
from PIL import Image
|
47 |
+
import timm
|
48 |
+
|
49 |
+
img = Image.open(urlopen(
|
50 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
51 |
+
))
|
52 |
+
|
53 |
+
model = timm.create_model('gernet_m.idstcv_in1k', pretrained=True)
|
54 |
+
model = model.eval()
|
55 |
+
|
56 |
+
# get model specific transforms (normalization, resize)
|
57 |
+
data_config = timm.data.resolve_model_data_config(model)
|
58 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
59 |
+
|
60 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
61 |
+
|
62 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
63 |
+
```
|
64 |
+
|
65 |
+
### Feature Map Extraction
|
66 |
+
```python
|
67 |
+
from urllib.request import urlopen
|
68 |
+
from PIL import Image
|
69 |
+
import timm
|
70 |
+
|
71 |
+
img = Image.open(urlopen(
|
72 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
73 |
+
))
|
74 |
+
|
75 |
+
model = timm.create_model(
|
76 |
+
'gernet_m.idstcv_in1k',
|
77 |
+
pretrained=True,
|
78 |
+
features_only=True,
|
79 |
+
)
|
80 |
+
model = model.eval()
|
81 |
+
|
82 |
+
# get model specific transforms (normalization, resize)
|
83 |
+
data_config = timm.data.resolve_model_data_config(model)
|
84 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
85 |
+
|
86 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
87 |
+
|
88 |
+
for o in output:
|
89 |
+
# print shape of each feature map in output
|
90 |
+
# e.g.:
|
91 |
+
# torch.Size([1, 32, 112, 112])
|
92 |
+
# torch.Size([1, 128, 56, 56])
|
93 |
+
# torch.Size([1, 192, 28, 28])
|
94 |
+
# torch.Size([1, 640, 14, 14])
|
95 |
+
# torch.Size([1, 2560, 7, 7])
|
96 |
+
|
97 |
+
print(o.shape)
|
98 |
+
```
|
99 |
+
|
100 |
+
### Image Embeddings
|
101 |
+
```python
|
102 |
+
from urllib.request import urlopen
|
103 |
+
from PIL import Image
|
104 |
+
import timm
|
105 |
+
|
106 |
+
img = Image.open(urlopen(
|
107 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
108 |
+
))
|
109 |
+
|
110 |
+
model = timm.create_model(
|
111 |
+
'gernet_m.idstcv_in1k',
|
112 |
+
pretrained=True,
|
113 |
+
num_classes=0, # remove classifier nn.Linear
|
114 |
+
)
|
115 |
+
model = model.eval()
|
116 |
+
|
117 |
+
# get model specific transforms (normalization, resize)
|
118 |
+
data_config = timm.data.resolve_model_data_config(model)
|
119 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
120 |
+
|
121 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
122 |
+
|
123 |
+
# or equivalently (without needing to set num_classes=0)
|
124 |
+
|
125 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
126 |
+
# output is unpooled, a (1, 2560, 7, 7) shaped tensor
|
127 |
+
|
128 |
+
output = model.forward_head(output, pre_logits=True)
|
129 |
+
# output is a (1, num_features) shaped tensor
|
130 |
+
```
|
131 |
+
|
132 |
+
## Model Comparison
|
133 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
134 |
+
|
135 |
+
## Citation
|
136 |
+
```bibtex
|
137 |
+
@misc{rw2019timm,
|
138 |
+
author = {Ross Wightman},
|
139 |
+
title = {PyTorch Image Models},
|
140 |
+
year = {2019},
|
141 |
+
publisher = {GitHub},
|
142 |
+
journal = {GitHub repository},
|
143 |
+
doi = {10.5281/zenodo.4414861},
|
144 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
145 |
+
}
|
146 |
+
```
|
147 |
+
```bibtex
|
148 |
+
@misc{lin2020neural,
|
149 |
+
title={Neural Architecture Design for GPU-Efficient Networks},
|
150 |
+
author={Ming Lin and Hesen Chen and Xiuyu Sun and Qi Qian and Hao Li and Rong Jin},
|
151 |
+
year={2020},
|
152 |
+
eprint={2006.14090},
|
153 |
+
archivePrefix={arXiv},
|
154 |
+
primaryClass={cs.CV}
|
155 |
+
}
|
156 |
+
```
|
config.json
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "gernet_m",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 2560,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "idstcv_in1k",
|
7 |
+
"custom_load": false,
|
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.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 |
+
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:4e3e1ee8c32a576b8ec76ec8071d7be6da9d6a97dfc5837ab9cbbb1c69dd3738
|
3 |
+
size 84866346
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94f8cdd54db14574c6a077a6d85616b9609803f32439c2af3d5b704e42a5cc6d
|
3 |
+
size 84938317
|