timm documentation

CrossViT

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

CrossViT

Category: ViT · Code: timm/models/crossvit.py · Architectures: 11 · Pretrained weights: 11 (11 with ImageNet-1k results)

CrossViT processes small and large image patches in two Transformer branches and fuses them with cross-attention through the class tokens. Model names in timm give the actual input resolution (240 / 408 instead of the original 224 / 384).

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('crossvit_small_240.in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)

Model API support

FeatureCrossVit
features_only=True feature maps✗
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 (CrossVit with crossvit_tiny_240 at 240), 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
crossvit_9_2408.551.852401
crossvit_9_dagger_2408.781.992401
crossvit_15_24027.535.812401
crossvit_15_dagger_24028.216.132401
crossvit_15_dagger_40828.5021.454081
crossvit_18_24043.279.052401
crossvit_18_dagger_24044.279.502401
crossvit_18_dagger_40844.6132.474081
crossvit_base_240105.0321.222401
crossvit_small_24026.865.632401
crossvit_tiny_2407.011.572401

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
crossvit_9_240.in1k24073.9942401000apache-2.0timm
crossvit_9_dagger_240.in1k24076.9902401000apache-2.0timm
crossvit_15_240.in1k24081.5222401000apache-2.0timm
crossvit_15_dagger_240.in1k24082.3022401000apache-2.0timm
crossvit_15_dagger_408.in1k40883.8424081000apache-2.0timm
crossvit_18_240.in1k24082.3902401000apache-2.0timm
crossvit_18_dagger_240.in1k24082.4942401000apache-2.0timm
crossvit_18_dagger_408.in1k40884.1984081000apache-2.0timm
crossvit_base_240.in1k24082.2122401000apache-2.0timm
crossvit_small_240.in1k24081.0362401000apache-2.0timm
crossvit_tiny_240.in1k24073.3522401000apache-2.0timm

Citation

@inproceedings{
    chen2021crossvit,
    title={{CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification}},
    author={Chun-Fu (Richard) Chen and Quanfu Fan and Rameswar Panda},
    booktitle={International Conference on Computer Vision (ICCV)},
    year={2021}
}
Update on GitHub