Add model
Browse files- README.md +131 -0
- config.json +36 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 pnasnet5large.tf_in1k
|
11 |
+
|
12 |
+
A PNasNet image classification model. Trained on ImageNet-1k by paper authors. Ported from Tensorflow via Cadene's pretrained-models.pytorch.
|
13 |
+
|
14 |
+
## Model Details
|
15 |
+
- **Model Type:** Image classification / feature backbone
|
16 |
+
- **Model Stats:**
|
17 |
+
- Params (M): 86.1
|
18 |
+
- GMACs: 25.0
|
19 |
+
- Activations (M): 92.9
|
20 |
+
- Image size: 331 x 331
|
21 |
+
- **Papers:**
|
22 |
+
- Progressive Neural Architecture Search: https://arxiv.org/abs/1712.00559
|
23 |
+
- **Original:**
|
24 |
+
- https://github.com/tensorflow/models
|
25 |
+
- https://github.com/Cadene/pretrained-models.pytorch
|
26 |
+
- **Dataset:** ImageNet-1k
|
27 |
+
|
28 |
+
## Model Usage
|
29 |
+
### Image Classification
|
30 |
+
```python
|
31 |
+
from urllib.request import urlopen
|
32 |
+
from PIL import Image
|
33 |
+
import timm
|
34 |
+
|
35 |
+
img = Image.open(urlopen(
|
36 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
37 |
+
))
|
38 |
+
|
39 |
+
model = timm.create_model('pnasnet5large.tf_in1k', pretrained=True)
|
40 |
+
model = model.eval()
|
41 |
+
|
42 |
+
# get model specific transforms (normalization, resize)
|
43 |
+
data_config = timm.data.resolve_model_data_config(model)
|
44 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
45 |
+
|
46 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
47 |
+
|
48 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
49 |
+
```
|
50 |
+
|
51 |
+
### Feature Map Extraction
|
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(
|
62 |
+
'pnasnet5large.tf_in1k',
|
63 |
+
pretrained=True,
|
64 |
+
features_only=True,
|
65 |
+
)
|
66 |
+
model = model.eval()
|
67 |
+
|
68 |
+
# get model specific transforms (normalization, resize)
|
69 |
+
data_config = timm.data.resolve_model_data_config(model)
|
70 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
71 |
+
|
72 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
73 |
+
|
74 |
+
for o in output:
|
75 |
+
# print shape of each feature map in output
|
76 |
+
# e.g.:
|
77 |
+
# torch.Size([1, 96, 165, 165])
|
78 |
+
# torch.Size([1, 270, 83, 83])
|
79 |
+
# torch.Size([1, 1080, 42, 42])
|
80 |
+
# torch.Size([1, 2160, 21, 21])
|
81 |
+
# torch.Size([1, 4320, 11, 11])
|
82 |
+
|
83 |
+
print(o.shape)
|
84 |
+
```
|
85 |
+
|
86 |
+
### Image Embeddings
|
87 |
+
```python
|
88 |
+
from urllib.request import urlopen
|
89 |
+
from PIL import Image
|
90 |
+
import timm
|
91 |
+
|
92 |
+
img = Image.open(urlopen(
|
93 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
94 |
+
))
|
95 |
+
|
96 |
+
model = timm.create_model(
|
97 |
+
'pnasnet5large.tf_in1k',
|
98 |
+
pretrained=True,
|
99 |
+
num_classes=0, # remove classifier nn.Linear
|
100 |
+
)
|
101 |
+
model = model.eval()
|
102 |
+
|
103 |
+
# get model specific transforms (normalization, resize)
|
104 |
+
data_config = timm.data.resolve_model_data_config(model)
|
105 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
106 |
+
|
107 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
108 |
+
|
109 |
+
# or equivalently (without needing to set num_classes=0)
|
110 |
+
|
111 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
112 |
+
# output is unpooled, a (1, 4320, 11, 11) shaped tensor
|
113 |
+
|
114 |
+
output = model.forward_head(output, pre_logits=True)
|
115 |
+
# output is a (1, num_features) shaped tensor
|
116 |
+
```
|
117 |
+
|
118 |
+
## Model Comparison
|
119 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
120 |
+
|
121 |
+
## Citation
|
122 |
+
```bibtex
|
123 |
+
@misc{liu2018progressive,
|
124 |
+
title={Progressive Neural Architecture Search},
|
125 |
+
author={Chenxi Liu and Barret Zoph and Maxim Neumann and Jonathon Shlens and Wei Hua and Li-Jia Li and Li Fei-Fei and Alan Yuille and Jonathan Huang and Kevin Murphy},
|
126 |
+
year={2018},
|
127 |
+
eprint={1712.00559},
|
128 |
+
archivePrefix={arXiv},
|
129 |
+
primaryClass={cs.CV}
|
130 |
+
}
|
131 |
+
```
|
config.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "pnasnet5large",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 4320,
|
5 |
+
"pretrained_cfg": {
|
6 |
+
"tag": "tf_in1k",
|
7 |
+
"custom_load": false,
|
8 |
+
"input_size": [
|
9 |
+
3,
|
10 |
+
331,
|
11 |
+
331
|
12 |
+
],
|
13 |
+
"fixed_input_size": false,
|
14 |
+
"interpolation": "bicubic",
|
15 |
+
"crop_pct": 0.911,
|
16 |
+
"crop_mode": "center",
|
17 |
+
"mean": [
|
18 |
+
0.5,
|
19 |
+
0.5,
|
20 |
+
0.5
|
21 |
+
],
|
22 |
+
"std": [
|
23 |
+
0.5,
|
24 |
+
0.5,
|
25 |
+
0.5
|
26 |
+
],
|
27 |
+
"num_classes": 1000,
|
28 |
+
"label_offset": 1,
|
29 |
+
"pool_size": [
|
30 |
+
11,
|
31 |
+
11
|
32 |
+
],
|
33 |
+
"first_conv": "conv_0.conv",
|
34 |
+
"classifier": "last_linear"
|
35 |
+
}
|
36 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d2716e3e655f6b58eb79e5734ed82e20de34d12d959abae4a81575fc2f7b448
|
3 |
+
size 345099940
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cab1d7a53799911a9cadd48817f959365dd197dbe67d03f225ea48f854936341
|
3 |
+
size 345446297
|