Yixiao Fang d80ec5a4b8
[Refactor] Refactor BEiT backbone and support v1/v2 inference. (#1144)
* refactor beit backbone

* use LinearClsHead

* fix mean and std value

* fix lint

* support inference if beit-v2

* update encoder layer and init

* update

* add ut

* add prepare_relative_position_bias_table function

* add cls_token

* fix lint

* add pos_embed check

* update metafile and readme

* update weights link

* update link of weights

* update metafile

* update

* update docstrings

* update according to review

* rename readme

* update docstring

* fix lint
2022-11-29 12:56:33 +08:00
..

BEiT

BEiT: BERT Pre-Training of Image Transformers

Abstract

We introduce a self-supervised vision representation model BEiT, which stands for Bidirectional Encoder representation from Image Transformers. Following BERT developed in the natural language processing area, we propose a masked image modeling task to pretrain vision Transformers. Specifically, each image has two views in our pre-training, i.e, image patches (such as 16x16 pixels), and visual tokens (i.e., discrete tokens). We first "tokenize" the original image into visual tokens. Then we randomly mask some image patches and fed them into the backbone Transformer. The pre-training objective is to recover the original visual tokens based on the corrupted image patches. After pre-training BEiT, we directly fine-tune the model parameters on downstream tasks by appending task layers upon the pretrained encoder. Experimental results on image classification and semantic segmentation show that our model achieves competitive results with previous pre-training methods. For example, base-size BEiT achieves 83.2% top-1 accuracy on ImageNet-1K, significantly outperforming from-scratch DeiT training (81.8%) with the same setup. Moreover, large-size BEiT obtains 86.3% only using ImageNet-1K, even outperforming ViT-L with supervised pre-training on ImageNet-22K (85.2%).

Results and models

ImageNet-1k

Model Pretrain Params(M) Flops(G) Top-1 (%) Top-5 (%) Config Download
BEiT-base* ImageNet-21k 86.53 17.58 85.28 97.59 config model

Models with * are converted from the official repo. The config files of these models are only for inference.

For BEiT self-supervised learning algorithm, welcome to MMSelfSup page to get more information.

Citation

@article{beit,
    title={{BEiT}: {BERT} Pre-Training of Image Transformers},
    author={Hangbo Bao and Li Dong and Furu Wei},
    year={2021},
    eprint={2106.08254},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}