Add model
Browse files- README.md +115 -0
- config.json +36 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 levit_192.fb_dist_in1k
|
11 |
+
|
12 |
+
A LeViT image classification model using convolutional mode (using nn.Conv2d and nn.BatchNorm2d). Pretrained on ImageNet-1k using distillation by paper authors.
|
13 |
+
|
14 |
+
|
15 |
+
## Model Details
|
16 |
+
- **Model Type:** Image classification / feature backbone
|
17 |
+
- **Model Stats:**
|
18 |
+
- Params (M): 10.9
|
19 |
+
- GMACs: 0.7
|
20 |
+
- Activations (M): 3.2
|
21 |
+
- Image size: 224 x 224
|
22 |
+
- **Papers:**
|
23 |
+
- LeViT: a Vision Transformer in ConvNet's Clothing for Faster Inference: https://arxiv.org/abs/2104.01136
|
24 |
+
- **Original:** https://github.com/facebookresearch/LeViT
|
25 |
+
- **Dataset:** ImageNet-1k
|
26 |
+
|
27 |
+
## Model Usage
|
28 |
+
### Image Classification
|
29 |
+
```python
|
30 |
+
from urllib.request import urlopen
|
31 |
+
from PIL import Image
|
32 |
+
import timm
|
33 |
+
|
34 |
+
img = Image.open(
|
35 |
+
urlopen('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'))
|
36 |
+
|
37 |
+
model = timm.create_model('levit_192.fb_dist_in1k', pretrained=True)
|
38 |
+
model = model.eval()
|
39 |
+
|
40 |
+
# get model specific transforms (normalization, resize)
|
41 |
+
data_config = timm.data.resolve_model_data_config(model)
|
42 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
43 |
+
|
44 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
45 |
+
|
46 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
47 |
+
```
|
48 |
+
|
49 |
+
### Image Embeddings
|
50 |
+
```python
|
51 |
+
from urllib.request import urlopen
|
52 |
+
from PIL import Image
|
53 |
+
import timm
|
54 |
+
|
55 |
+
img = Image.open(
|
56 |
+
urlopen('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'))
|
57 |
+
|
58 |
+
model = timm.create_model(
|
59 |
+
'levit_192.fb_dist_in1k',
|
60 |
+
pretrained=True,
|
61 |
+
num_classes=0, # remove classifier nn.Linear
|
62 |
+
)
|
63 |
+
model = model.eval()
|
64 |
+
|
65 |
+
# get model specific transforms (normalization, resize)
|
66 |
+
data_config = timm.data.resolve_model_data_config(model)
|
67 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
68 |
+
|
69 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
70 |
+
|
71 |
+
# or equivalently (without needing to set num_classes=0)
|
72 |
+
|
73 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
74 |
+
# output is unpooled (ie.e a (batch_size, num_features, H, W) tensor
|
75 |
+
|
76 |
+
output = model.forward_head(output, pre_logits=True)
|
77 |
+
# output is (batch_size, num_features) tensor
|
78 |
+
```
|
79 |
+
|
80 |
+
## Model Comparison
|
81 |
+
|model |top1 |top5 |param_count|img_size|
|
82 |
+
|-----------------------------------|------|------|-----------|--------|
|
83 |
+
|levit_384.fb_dist_in1k |82.596|96.012|39.13 |224 |
|
84 |
+
|levit_conv_384.fb_dist_in1k |82.596|96.012|39.13 |224 |
|
85 |
+
|levit_256.fb_dist_in1k |81.512|95.48 |18.89 |224 |
|
86 |
+
|levit_conv_256.fb_dist_in1k |81.512|95.48 |18.89 |224 |
|
87 |
+
|levit_conv_192.fb_dist_in1k |79.86 |94.792|10.95 |224 |
|
88 |
+
|levit_192.fb_dist_in1k |79.858|94.792|10.95 |224 |
|
89 |
+
|levit_128.fb_dist_in1k |78.474|94.014|9.21 |224 |
|
90 |
+
|levit_conv_128.fb_dist_in1k |78.474|94.02 |9.21 |224 |
|
91 |
+
|levit_128s.fb_dist_in1k |76.534|92.864|7.78 |224 |
|
92 |
+
|levit_conv_128s.fb_dist_in1k |76.532|92.864|7.78 |224 |
|
93 |
+
|
94 |
+
## Citation
|
95 |
+
```bibtex
|
96 |
+
@InProceedings{Graham_2021_ICCV,
|
97 |
+
author = {Graham, Benjamin and El-Nouby, Alaaeldin and Touvron, Hugo and Stock, Pierre and Joulin, Armand and Jegou, Herve and Douze, Matthijs},
|
98 |
+
title = {LeViT: A Vision Transformer in ConvNet's Clothing for Faster Inference},
|
99 |
+
booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
|
100 |
+
month = {October},
|
101 |
+
year = {2021},
|
102 |
+
pages = {12259-12269}
|
103 |
+
}
|
104 |
+
```
|
105 |
+
```bibtex
|
106 |
+
@misc{rw2019timm,
|
107 |
+
author = {Ross Wightman},
|
108 |
+
title = {PyTorch Image Models},
|
109 |
+
year = {2019},
|
110 |
+
publisher = {GitHub},
|
111 |
+
journal = {GitHub repository},
|
112 |
+
doi = {10.5281/zenodo.4414861},
|
113 |
+
howpublished = {\url{https://github.com/rwightman/pytorch-image-models}}
|
114 |
+
}
|
115 |
+
```
|
config.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "levit_192",
|
3 |
+
"num_classes": 1000,
|
4 |
+
"num_features": 384,
|
5 |
+
"global_pool": "avg",
|
6 |
+
"pretrained_cfg": {
|
7 |
+
"tag": "fb_dist_in1k",
|
8 |
+
"custom_load": false,
|
9 |
+
"input_size": [
|
10 |
+
3,
|
11 |
+
224,
|
12 |
+
224
|
13 |
+
],
|
14 |
+
"fixed_input_size": true,
|
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": null,
|
30 |
+
"first_conv": "stem.conv1.linear",
|
31 |
+
"classifier": [
|
32 |
+
"head.linear",
|
33 |
+
"head_dist.linear"
|
34 |
+
]
|
35 |
+
}
|
36 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7a418f41267b7fe6928c013b8ceff8166743bfbc5eeb5d17a52fcbe10db499a2
|
3 |
+
size 44153613
|