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 |
+
- video-classification
|
6 |
+
datasets:
|
7 |
+
- kinetics-400
|
8 |
+
- kinetics-600
|
9 |
+
- something-something-v1
|
10 |
+
- something-something-v2
|
11 |
---
|
12 |
+
|
13 |
+
# UniFormer (video model)
|
14 |
+
|
15 |
+
UniFormer models are trained on [Kinetics](https://deepmind.com/research/open-source/kinetics) and [Something-Something](https://20bn.com/datasets/something-something) at resolution 224x224.
|
16 |
+
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,
|
17 |
+
and first released in [this repository](https://github.com/Sense-X/UniFormer).
|
18 |
+
|
19 |
+
|
20 |
+
## Model description
|
21 |
+
|
22 |
+
The UniFormer is a type of Vision Transformer, which can seamlessly integrate merits of convolution and self-attention in a concise transformer format.
|
23 |
+
It adopt local MHRA in shallow layers to largely reduce computation burden and global MHRA in deep layers to learn global token relation.
|
24 |
+
|
25 |
+
Without any extra training data,
|
26 |
+
UniFormer achieves **86.3** top-1 accuracy on ImageNet-1K classification.
|
27 |
+
With only ImageNet-1K pre-training, it can simply achieve state-of-the-art performance in a broad range of downstream tasks.
|
28 |
+
UniFormer obtains **82.9/84.8** top-1 accuracy on Kinetics-400/600,
|
29 |
+
and **60.9/71.2** top-1 accuracy on Something-Something V1/V2 video classification tasks.
|
30 |
+
It also achieves **53.8** box AP and **46.4** mask AP on COCO object detection task,
|
31 |
+
**50.8** mIoU on ADE20K semantic segmentation task,
|
32 |
+
and **77.4** AP on COCO pose estimation task.
|
33 |
+
|
34 |
+
![model image](https://github.com/Sense-X/UniFormer/blob/main/figures/framework.png)
|
35 |
+
|
36 |
+
[Source](https://paperswithcode.com/paper/uniformer-unifying-convolution-and-self)
|
37 |
+
|
38 |
+
## Intended uses & limitations
|
39 |
+
|
40 |
+
You can use the raw model for video classification.
|
41 |
+
We now only upload the powerful models with **single clip**.
|
42 |
+
More models can be found in [the model hub](https://github.com/Sense-X/UniFormer/tree/main/video_classification).
|
43 |
+
|
44 |
+
### Kinetics
|
45 |
+
| Model | #Frame | Sampling Stride | FLOPs | K400 Top-1 | K600 Top-1 |
|
46 |
+
| ----------- | ------ | --------------- | ----- | ---------- | ---------- |
|
47 |
+
| UniFormer-S | 16x1x1 | 8 | 41.8G | 78.4 | 80.8 |
|
48 |
+
| UniFormer-B | 16x1x1 | 8 | 96.7G | 79.3 | 81.7 |
|
49 |
+
| UniFormer-B | 32x1x1 | 4 | 259G | 80.9 | 82.4 |
|
50 |
+
|
51 |
+
|
52 |
+
### Something-Something
|
53 |
+
| Model | #Frame | FLOPs | SSV1 Top-1 | SSV2 Top-1 |
|
54 |
+
| ----------- | ------ | ----- | ---------- | ---------- |
|
55 |
+
| UniFormer-S | 16x1x1 | 41.8G | 54.4 | 65.0 |
|
56 |
+
| UniFormer-B | 32x1x1 | 259G | 58.0 | 67.5 |
|
57 |
+
|
58 |
+
|
59 |
+
### How to use
|
60 |
+
|
61 |
+
You can followed our [demo](https://huggingface.co/spaces/Sense-X/uniformer_image_demo/tree/main) to use our models.
|
62 |
+
|
63 |
+
```python
|
64 |
+
from uniformer import uniformer_small
|
65 |
+
from kinetics_class_index import kinetics_classnames
|
66 |
+
|
67 |
+
|
68 |
+
model = uniformer_small()
|
69 |
+
# load state
|
70 |
+
model_path = hf_hub_download(repo_id="Sense-X/uniformer_video", filename="uniformer_small_k400_16x8.pth")
|
71 |
+
state_dict = torch.load(model_path, map_location='cpu')
|
72 |
+
model.load_state_dict(state_dict)
|
73 |
+
# set to eval mode
|
74 |
+
model = model.to(device)
|
75 |
+
model = model.eval()
|
76 |
+
|
77 |
+
# please refer to the following url to process video of Kinetics:
|
78 |
+
# https://huggingface.co/spaces/Sense-X/uniformer_video_demo/blob/main/app.py
|
79 |
+
vid = load_video(video)
|
80 |
+
|
81 |
+
# model predicts one of the 400 Kintics classes
|
82 |
+
prediction = model(vid)
|
83 |
+
predicted_class_idx = prediction.flatten().argmax(-1).item()
|
84 |
+
print("Predicted class:", kinetics_classnames[str(predicted_class_idx)])
|
85 |
+
```
|
86 |
+
|
87 |
+
|
88 |
+
### BibTeX entry and citation info
|
89 |
+
|
90 |
+
```bibtex
|
91 |
+
@misc{li2022uniformer,
|
92 |
+
title={UniFormer: Unified Transformer for Efficient Spatiotemporal Representation Learning},
|
93 |
+
author={Kunchang Li and Yali Wang and Peng Gao and Guanglu Song and Yu Liu and Hongsheng Li and Yu Qiao},
|
94 |
+
year={2022},
|
95 |
+
eprint={2201.04676},
|
96 |
+
archivePrefix={arXiv},
|
97 |
+
primaryClass={cs.CV}
|
98 |
+
}
|
99 |
+
```
|