Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,99 @@
|
|
1 |
---
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
+
tags:
|
4 |
+
- vision
|
5 |
+
- image-classification
|
6 |
+
datasets:
|
7 |
+
- imagenet
|
8 |
---
|
9 |
+
|
10 |
+
# UniFormer (image model)
|
11 |
+
|
12 |
+
UniFormer models are trained on ImageNet at resolution 224x224.
|
13 |
+
It was introduced in the paper [UniFormer: Unifying Convolution and Self-attention for Visual Recognition](https://arxiv.org/abs/2201.09450) by Li et al,
|
14 |
+
and first released in [this repository](https://github.com/Sense-X/UniFormer).
|
15 |
+
|
16 |
+
|
17 |
+
## Model description
|
18 |
+
|
19 |
+
The UniFormer is a type of Vision Transformer, which can seamlessly integrate merits of convolution and self-attention in a concise transformer format.
|
20 |
+
It adopt local MHRA in shallow layers to largely reduce computation burden and global MHRA in deep layers to learn global token relation.
|
21 |
+
|
22 |
+
Without any extra training data,
|
23 |
+
UniFormer achieves **86.3** top-1 accuracy on ImageNet-1K classification.
|
24 |
+
With only ImageNet-1K pre-training, it can simply achieve state-of-the-art performance in a broad range of downstream tasks.
|
25 |
+
UniFormer obtains **82.9/84.8** top-1 accuracy on Kinetics-400/600,
|
26 |
+
and **60.9/71.2** top-1 accuracy on Something-Something V1/V2 video classification tasks.
|
27 |
+
It also achieves **53.8** box AP and **46.4** mask AP on COCO object detection task,
|
28 |
+
**50.8** mIoU on ADE20K semantic segmentation task,
|
29 |
+
and **77.4** AP on COCO pose estimation task.
|
30 |
+
|
31 |
+
![teaser](framework.png)
|
32 |
+
|
33 |
+
[Source](https://paperswithcode.com/paper/uniformer-unifying-convolution-and-self)
|
34 |
+
|
35 |
+
## Intended uses & limitations
|
36 |
+
|
37 |
+
You can use the raw model for image classification.
|
38 |
+
We now only upload the models trained without Token Labeling and Layer Scale.
|
39 |
+
More powerful models can be found in [the model hub](https://github.com/Sense-X/UniFormer/tree/main/image_classification).
|
40 |
+
|
41 |
+
### ImageNet
|
42 |
+
| Model | Pretrain | Resolution | Top-1 | #Param. | FLOPs |
|
43 |
+
| --------------- | ----------- | ---------- | ----- | ------- | ----- |
|
44 |
+
| UniFormer-S | ImageNet-1K | 224x224 | 82.9 | 22M | 3.6G |
|
45 |
+
| UniFormer-S† | ImageNet-1K | 224x224 | 83.4 | 24M | 4.2G |
|
46 |
+
| UniFormer-B | ImageNet-1K | 224x224 | 83.8 | 50M | 8.3G |
|
47 |
+
|
48 |
+
|
49 |
+
### How to use
|
50 |
+
|
51 |
+
You can followed our [demo](https://huggingface.co/spaces/Sense-X/uniformer_image_demo/tree/main) to use our models.
|
52 |
+
|
53 |
+
```python
|
54 |
+
from uniformer import uniformer_small
|
55 |
+
from imagenet_class_index import imagenet_classnames
|
56 |
+
|
57 |
+
|
58 |
+
model = uniformer_small()
|
59 |
+
# load state
|
60 |
+
model_path = hf_hub_download(repo_id="Sense-X/uniformer_image", filename="uniformer_small_in1k.pth")
|
61 |
+
state_dict = torch.load(model_path, map_location='cpu')
|
62 |
+
model.load_state_dict(state_dict)
|
63 |
+
# set to eval mode
|
64 |
+
model = model.to(device)
|
65 |
+
model = model.eval()
|
66 |
+
|
67 |
+
# process image
|
68 |
+
image = img
|
69 |
+
image_transform = T.Compose(
|
70 |
+
[
|
71 |
+
T.Resize(224),
|
72 |
+
T.CenterCrop(224),
|
73 |
+
T.ToTensor(),
|
74 |
+
T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
75 |
+
]
|
76 |
+
)
|
77 |
+
image = image_transform(image)
|
78 |
+
image = image.unsqueeze(0)
|
79 |
+
|
80 |
+
|
81 |
+
# model predicts one of the 1000 ImageNet classes
|
82 |
+
prediction = model(image)
|
83 |
+
predicted_class_idx = prediction.flatten().argmax(-1).item()
|
84 |
+
print("Predicted class:", imagenet_classnames[str(predicted_class_idx)][1])
|
85 |
+
```
|
86 |
+
|
87 |
+
|
88 |
+
### BibTeX entry and citation info
|
89 |
+
|
90 |
+
```bibtex
|
91 |
+
@misc{li2022uniformer,
|
92 |
+
title={UniFormer: Unifying Convolution and Self-attention for Visual Recognition},
|
93 |
+
author={Kunchang Li and Yali Wang and Junhao Zhang and Peng Gao and Guanglu Song and Yu Liu and Hongsheng Li and Yu Qiao},
|
94 |
+
year={2022},
|
95 |
+
eprint={2201.09450},
|
96 |
+
archivePrefix={arXiv},
|
97 |
+
primaryClass={cs.CV}
|
98 |
+
}
|
99 |
+
```
|