Add model
Browse files- README.md +114 -0
- config.json +33 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
README.md
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- image-classification
|
4 |
+
- timm
|
5 |
+
library_tag: timm
|
6 |
+
license: apache-2.0
|
7 |
+
datasets:
|
8 |
+
- imagenet-21k
|
9 |
+
---
|
10 |
+
# Model card for mixer_b16_224.miil_in21k
|
11 |
+
|
12 |
+
A MLP-Mixer image classification model. Trained on ImageNet-21k by [Alibaba-MIIL](https://github.com/Alibaba-MIIL).
|
13 |
+
|
14 |
+
## Model Details
|
15 |
+
- **Model Type:** Image classification / feature backbone
|
16 |
+
- **Model Stats:**
|
17 |
+
- Params (M): 67.7
|
18 |
+
- GMACs: 12.6
|
19 |
+
- Activations (M): 14.5
|
20 |
+
- Image size: 224 x 224
|
21 |
+
- **Papers:**
|
22 |
+
- MLP-Mixer: An all-MLP Architecture for Vision: https://arxiv.org/abs/2105.01601
|
23 |
+
- ImageNet-21K Pretraining for the Masses: https://arxiv.org/abs/2104.10972
|
24 |
+
- **Original:** https://github.com/Alibaba-MIIL/ImageNet21K
|
25 |
+
- **Dataset:** ImageNet-21k
|
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(urlopen(
|
35 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
36 |
+
))
|
37 |
+
|
38 |
+
model = timm.create_model('mixer_b16_224.miil_in21k', pretrained=True)
|
39 |
+
model = model.eval()
|
40 |
+
|
41 |
+
# get model specific transforms (normalization, resize)
|
42 |
+
data_config = timm.data.resolve_model_data_config(model)
|
43 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
44 |
+
|
45 |
+
output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
|
46 |
+
|
47 |
+
top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
|
48 |
+
```
|
49 |
+
|
50 |
+
### Image Embeddings
|
51 |
+
```python
|
52 |
+
from urllib.request import urlopen
|
53 |
+
from PIL import Image
|
54 |
+
import timm
|
55 |
+
|
56 |
+
img = Image.open(urlopen(
|
57 |
+
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
|
58 |
+
))
|
59 |
+
|
60 |
+
model = timm.create_model(
|
61 |
+
'mixer_b16_224.miil_in21k',
|
62 |
+
pretrained=True,
|
63 |
+
num_classes=0, # remove classifier nn.Linear
|
64 |
+
)
|
65 |
+
model = model.eval()
|
66 |
+
|
67 |
+
# get model specific transforms (normalization, resize)
|
68 |
+
data_config = timm.data.resolve_model_data_config(model)
|
69 |
+
transforms = timm.data.create_transform(**data_config, is_training=False)
|
70 |
+
|
71 |
+
output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
|
72 |
+
|
73 |
+
# or equivalently (without needing to set num_classes=0)
|
74 |
+
|
75 |
+
output = model.forward_features(transforms(img).unsqueeze(0))
|
76 |
+
# output is unpooled, a (1, 196, 768) shaped tensor
|
77 |
+
|
78 |
+
output = model.forward_head(output, pre_logits=True)
|
79 |
+
# output is a (1, num_features) shaped tensor
|
80 |
+
```
|
81 |
+
|
82 |
+
## Model Comparison
|
83 |
+
Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
|
84 |
+
|
85 |
+
## Citation
|
86 |
+
```bibtex
|
87 |
+
@article{tolstikhin2021mixer,
|
88 |
+
title={MLP-Mixer: An all-MLP Architecture for Vision},
|
89 |
+
author={Tolstikhin, Ilya and Houlsby, Neil and Kolesnikov, Alexander and Beyer, Lucas and Zhai, Xiaohua and Unterthiner, Thomas and Yung, Jessica and Steiner, Andreas and Keysers, Daniel and Uszkoreit, Jakob and Lucic, Mario and Dosovitskiy, Alexey},
|
90 |
+
journal={arXiv preprint arXiv:2105.01601},
|
91 |
+
year={2021}
|
92 |
+
}
|
93 |
+
```
|
94 |
+
```bibtex
|
95 |
+
@misc{ridnik2021imagenet21k,
|
96 |
+
title={ImageNet-21K Pretraining for the Masses},
|
97 |
+
author={Tal Ridnik and Emanuel Ben-Baruch and Asaf Noy and Lihi Zelnik-Manor},
|
98 |
+
year={2021},
|
99 |
+
eprint={2104.10972},
|
100 |
+
archivePrefix={arXiv},
|
101 |
+
primaryClass={cs.CV}
|
102 |
+
}
|
103 |
+
```
|
104 |
+
```bibtex
|
105 |
+
@misc{rw2019timm,
|
106 |
+
author = {Ross Wightman},
|
107 |
+
title = {PyTorch Image Models},
|
108 |
+
year = {2019},
|
109 |
+
publisher = {GitHub},
|
110 |
+
journal = {GitHub repository},
|
111 |
+
doi = {10.5281/zenodo.4414861},
|
112 |
+
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
|
113 |
+
}
|
114 |
+
```
|
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architecture": "mixer_b16_224",
|
3 |
+
"num_classes": 11221,
|
4 |
+
"num_features": 768,
|
5 |
+
"global_pool": "avg",
|
6 |
+
"pretrained_cfg": {
|
7 |
+
"tag": "miil_in21k",
|
8 |
+
"custom_load": false,
|
9 |
+
"input_size": [
|
10 |
+
3,
|
11 |
+
224,
|
12 |
+
224
|
13 |
+
],
|
14 |
+
"fixed_input_size": true,
|
15 |
+
"interpolation": "bilinear",
|
16 |
+
"crop_pct": 0.875,
|
17 |
+
"crop_mode": "center",
|
18 |
+
"mean": [
|
19 |
+
0.0,
|
20 |
+
0.0,
|
21 |
+
0.0
|
22 |
+
],
|
23 |
+
"std": [
|
24 |
+
1.0,
|
25 |
+
1.0,
|
26 |
+
1.0
|
27 |
+
],
|
28 |
+
"num_classes": 11221,
|
29 |
+
"pool_size": null,
|
30 |
+
"first_conv": "stem.proj",
|
31 |
+
"classifier": "head"
|
32 |
+
}
|
33 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2a168e46ca715cb3bcb066033a759b299a3de18a458b692dece9711c8af20419
|
3 |
+
size 270976234
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3b8265ff9177599a464ae4578f8db42cf23a332243aed9794212cb308d4fd51d
|
3 |
+
size 271017509
|