Add model
Browse files- README.md +125 -0
- config.json +36 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
library_name: timm
|
6 |
+
license: other
|
7 |
+
datasets:
|
8 |
+
- imagenet-1k
|
9 |
+
---
|
10 |
+
# Model card for fastvit_t8.apple_dist_in1k
|
11 |
+
|
12 |
+
A FastViT image classification model. Trained on ImageNet-1k with distillation by paper authors.
|
13 |
+
|
14 |
+
Please observe [original license](https://github.com/apple/ml-fastvit/blob/8af5928238cab99c45f64fc3e4e7b1516b8224ba/LICENSE).
|
15 |
+
|
16 |
+
## Model Details
|
17 |
+
- **Model Type:** Image classification / feature backbone
|
18 |
+
- **Model Stats:**
|
19 |
+
- Params (M): 4.0
|
20 |
+
- GMACs: 0.7
|
21 |
+
- Activations (M): 8.6
|
22 |
+
- Image size: 256 x 256
|
23 |
+
- **Papers:**
|
24 |
+
- FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization: https://arxiv.org/abs/2303.14189
|
25 |
+
- **Original:** https://github.com/apple/ml-fastvit
|
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('fastvit_t8.apple_dist_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 |
+
'fastvit_t8.apple_dist_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, 48, 64, 64])
|
78 |
+
# torch.Size([1, 96, 32, 32])
|
79 |
+
# torch.Size([1, 192, 16, 16])
|
80 |
+
# torch.Size([1, 384, 8, 8])
|
81 |
+
|
82 |
+
print(o.shape)
|
83 |
+
```
|
84 |
+
|
85 |
+
### Image Embeddings
|
86 |
+
```python
|
87 |
+
from urllib.request import urlopen
|
88 |
+
from PIL import Image
|
89 |
+
import timm
|
90 |
+
|
91 |
+
img = Image.open(urlopen(
|
92 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
93 |
+
))
|
94 |
+
|
95 |
+
model = timm.create_model(
|
96 |
+
'fastvit_t8.apple_dist_in1k',
|
97 |
+
pretrained=True,
|
98 |
+
num_classes=0, # remove classifier nn.Linear
|
99 |
+
)
|
100 |
+
model = model.eval()
|
101 |
+
|
102 |
+
# get model specific transforms (normalization, resize)
|
103 |
+
data_config = timm.data.resolve_model_data_config(model)
|
104 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
105 |
+
|
106 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
107 |
+
|
108 |
+
# or equivalently (without needing to set num_classes=0)
|
109 |
+
|
110 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
111 |
+
# output is unpooled, a (1, 384, 8, 8) shaped tensor
|
112 |
+
|
113 |
+
output = model.forward_head(output, pre_logits=True)
|
114 |
+
# output is a (1, num_features) shaped tensor
|
115 |
+
```
|
116 |
+
|
117 |
+
## Citation
|
118 |
+
```bibtex
|
119 |
+
@inproceedings{vasufastvit2023,
|
120 |
+
author = {Pavan Kumar Anasosalu Vasu and James Gabriel and Jeff Zhu and Oncel Tuzel and Anurag Ranjan},
|
121 |
+
title = {FastViT: A Fast Hybrid Vision Transformer using Structural Reparameterization},
|
122 |
+
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
|
123 |
+
year = {2023}
|
124 |
+
}
|
125 |
+
```
|
config.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "fastvit_t8",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 768,
|
5 |
+
"global_pool": "avg",
|
6 |
+
"pretrained_cfg": {
|
7 |
+
"tag": "apple_dist_in1k",
|
8 |
+
"custom_load": false,
|
9 |
+
"input_size": [
|
10 |
+
3,
|
11 |
+
256,
|
12 |
+
256
|
13 |
+
],
|
14 |
+
"fixed_input_size": false,
|
15 |
+
"interpolation": "bicubic",
|
16 |
+
"crop_pct": 0.9,
|
17 |
+
"crop_mode": "center",
|
18 |
+
"mean": [
|
19 |
+
0.485,
|
20 |
+
0.456,
|
21 |
+
0.406
|
22 |
+
],
|
23 |
+
"std": [
|
24 |
+
0.229,
|
25 |
+
0.224,
|
26 |
+
0.225
|
27 |
+
],
|
28 |
+
"num_classes": 1000,
|
29 |
+
"pool_size": [
|
30 |
+
8,
|
31 |
+
8
|
32 |
+
],
|
33 |
+
"first_conv": null,
|
34 |
+
"classifier": "head.fc"
|
35 |
+
}
|
36 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e31da81a225d20bc9e326baf1cc88ccc0e68fe2c43ea0154a870c409747f6aa
|
3 |
+
size 16266976
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ed2cf86e92335fcf5fc626c346e2d25df37727d54f0b46233d08b05c76e4ce76
|
3 |
+
size 16393221
|