timm documentation

BEiT

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v1.0.30).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

BEiT

Category: ViT · Code: timm/models/beit.py · Architectures: 7 · Pretrained weights: 13 (9 with ImageNet-1k results)

BEiT and BEiT-v2 Vision Transformers, pretrained with masked image modeling. BEiT predicts the discrete visual tokens of masked patches, BEiT-v2 uses a vector-quantized visual tokenizer for the targets. The weights here are fine-tuned classification weights.

Papers

Usage

See the Quickstart for loading pretrained weights, image preprocessing and fine-tuning, and Feature Extraction for using the models as backbones.

>>> import timm
>>> model = timm.create_model('beit_base_patch16_224.in22k_ft_in22k_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)

Model API support

FeatureBeit
features_only=True feature maps✓ (strides 16, 16, 16)
forward_intermediates()✓
prune_intermediate_layers()✓
Any input size, no changes needed✗
set_input_size()✓
dynamic_img_size=True✗
set_grad_checkpointing()✓
Layer-wise LR decay (group_matcher())✓
reset_classifier()✓

✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input size). Checked by running each feature on a randomly initialized model (Beit with beit_base_patch16_224 at 224), other architectures of the same class are expected to behave the same. See the Model API page for details.

Architectures

ArchitectureParams (M)GMACsInput sizePretrained weights
beit_base_patch16_22486.5317.582242
beit_base_patch16_38486.7455.543841
beit_large_patch16_224304.4361.602242
beit_large_patch16_384305.00191.213841
beit_large_patch16_512305.67362.245121
beitv2_base_patch16_22486.5317.582243
beitv2_large_patch16_224304.4361.602243

GMACs and parameter counts are for the default input size and classifier of each architecture, from the benchmark results.

Pretrained weights

Top-1 is ImageNet-1k validation accuracy from results-imagenet.csv at the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the size of the pretrained classifier, none for weights without one.

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
beit_base_patch16_224.in22k_ft_in22k224--21841apache-2.0timm
beit_base_patch16_224.in22k_ft_in22k_in1k22485.2382241000apache-2.0timm
beit_base_patch16_384.in22k_ft_in22k_in1k38486.8143841000apache-2.0timm
beit_large_patch16_224.in22k_ft_in22k224--21841apache-2.0timm
beit_large_patch16_224.in22k_ft_in22k_in1k22487.4862241000apache-2.0timm
beit_large_patch16_384.in22k_ft_in22k_in1k38488.3803841000apache-2.0timm
beit_large_patch16_512.in22k_ft_in22k_in1k51288.5765121000apache-2.0timm
beitv2_base_patch16_224.in1k_ft_in1k22485.5962241000apache-2.0timm
beitv2_base_patch16_224.in1k_ft_in22k224--21841apache-2.0timm
beitv2_base_patch16_224.in1k_ft_in22k_in1k22486.4942241000apache-2.0timm
beitv2_large_patch16_224.in1k_ft_in1k22487.4142241000apache-2.0timm
beitv2_large_patch16_224.in1k_ft_in22k224--21841apache-2.0timm
beitv2_large_patch16_224.in1k_ft_in22k_in1k22488.4062241000apache-2.0timm

Citation

@inproceedings{beit,
title={{BEiT}: {BERT} Pre-Training of Image Transformers},
author={Hangbo Bao and Li Dong and Songhao Piao and Furu Wei},
booktitle={International Conference on Learning Representations},
year={2022},
url={https://openreview.net/forum?id=p-BhZSz59o4}
}

@article{beitv2,
title={{BEiT v2}: Masked Image Modeling with Vector-Quantized Visual Tokenizers},
author={Zhiliang Peng and Li Dong and Hangbo Bao and Qixiang Ye and Furu Wei},
year={2022},
eprint={2208.06366},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Update on GitHub