timm/models/crossvit.py ·
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
- CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification
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
| Feature | CrossVit |
|---|---|
features_only=True feature maps |
✓ (strides 12, 17) |
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
| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---|---|---|---|
crossvit_9_240 |
8.55 | 1.85 | 240 | 1 |
crossvit_9_dagger_240 |
8.78 | 1.99 | 240 | 1 |
crossvit_15_240 |
27.53 | 5.81 | 240 | 1 |
crossvit_15_dagger_240 |
28.21 | 6.13 | 240 | 1 |
crossvit_15_dagger_408 |
28.50 | 21.45 | 408 | 1 |
crossvit_18_240 |
43.27 | 9.05 | 240 | 1 |
crossvit_18_dagger_240 |
44.27 | 9.50 | 240 | 1 |
crossvit_18_dagger_408 |
44.61 | 32.47 | 408 | 1 |
crossvit_base_240 |
105.03 | 21.22 | 240 | 1 |
crossvit_small_240 |
26.86 | 5.63 | 240 | 1 |
crossvit_tiny_240 |
7.01 | 1.57 | 240 | 1 |
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.
| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---|---|---|---|---|---|
crossvit_9_240.in1k |
240 | 73.994 | 240 | 1000 | apache-2.0 | timm |
crossvit_9_dagger_240.in1k |
240 | 76.990 | 240 | 1000 | apache-2.0 | timm |
crossvit_15_240.in1k |
240 | 81.522 | 240 | 1000 | apache-2.0 | timm |
crossvit_15_dagger_240.in1k |
240 | 82.302 | 240 | 1000 | apache-2.0 | timm |
crossvit_15_dagger_408.in1k |
408 | 83.842 | 408 | 1000 | apache-2.0 | timm |
crossvit_18_240.in1k |
240 | 82.390 | 240 | 1000 | apache-2.0 | timm |
crossvit_18_dagger_240.in1k |
240 | 82.494 | 240 | 1000 | apache-2.0 | timm |
crossvit_18_dagger_408.in1k |
408 | 84.198 | 408 | 1000 | apache-2.0 | timm |
crossvit_base_240.in1k |
240 | 82.212 | 240 | 1000 | apache-2.0 | timm |
crossvit_small_240.in1k |
240 | 81.036 | 240 | 1000 | apache-2.0 | timm |
crossvit_tiny_240.in1k |
240 | 73.352 | 240 | 1000 | apache-2.0 | timm |
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}
}
Source and license
Source: timm documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.