# CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification

Cross-attention lets two transformer branches exchange multi-scale image features

Chun-Fu Chen, Quanfu Fan, Rameswar Panda · arXiv · 2021-3-27

- **Problem** Vision Transformers face a trade-off between patch size and cost: finer patches improve accuracy but raise FLOPs sharply. Single-scale token sets cannot use both scales at once, and naive fusion of all tokens grows quadratically.
- **Method** CrossViT runs a large-patch branch and a small-patch branch in parallel. Each branch's CLS token alone queries the other branch's tokens through cross-attention, which keeps the cost linear.
- **Results** CrossViT-18 scored 91.36 on CIFAR100 in transfer learning, on par with DeiT-S at 90.89. The authors report 2% gain over DeiT on ImageNet1K.

## Why patch size is a trade-off

A Vision Transformer cuts an image into patches, projects each patch into a token, and then runs self-attention over the token sequence, so the patch size fixes how fine the representation is. Finer patches improve accuracy, but the cost rises quickly: the authors report that a patch size of 16 beats a patch size of 32 by 6%, while the finer setting needs 4 times more FLOPs.

Multi-scale features have helped convolutional networks in tasks such as detection and efficient inference, for example in Big-Little Net and Octave convolutions, yet their use in vision transformers was largely unexplored at the time.

The study therefore asks whether tokens from two patch sizes, handled by two branches of different cost, can be fused several times inside a transformer to give better classification features. The fusion step is the part that has to stay cheap, because a naive join of all tokens makes the attention cost grow quadratically with the token count.

## Two branches and their stacking

CrossViT is a stack of K multi-scale transformer encoders, and each of these encoders contains an L-branch and an S-branch. The L-branch uses the coarse patch size Pl with more transformer encoders and wider embeddings, while the S-branch uses the fine patch size Ps with fewer encoders and narrower embeddings, where Ps is smaller than Pl.

For the CrossViT-S configuration the small patch is 12, the large patch is 16, the embedding dimensions are 192 and 384, and K is 3 with N, M and L equal to 1, 4 and 1.

Each branch receives its own CLS token, and position embeddings are added to every token, including the CLS token, before the first multi-scale encoder. At the end the two CLS tokens are combined and passed to the classification head, so the prediction uses one summary per branch. The depth is set by the branch sizes: CrossViT-15 has 3 multi-scale encoders with 5 regular transformer encoders each, giving 15 encoders in the large branch.

## How cross-attention moves information between branches

The procedure is written for the L-branch and is repeated for the S-branch with the two indices swapped. The L-branch first projects its own CLS token with a projection f, concatenates it with the patch tokens of the S-branch, and gets the input for the attention step. \\\\(x'^{l} = \[\\\\, f^{l}(x^{l}\_{cls}) \\\\,\\\\\|\\\\, x^{s}\_{patch}\\\\,\]\\\\)

Only the projected CLS token is used as the query, so the attention map has one row per head and its cost is linear in the number of tokens rather than quadratic. \\\\(q = x'^{l}\_{cls} W\_q,\\\\; k = x'^{l} W\_k,\\\\; v = x'^{l} W\_v\\\\), with \\\\(W\_q, W\_k, W\_v\\\\) learnable and of size \\\\(C \\\\times (C/h)\\\\), where C is the embedding dimension and h the number of heads.

\\\\(A = \\\\mathrm{softmax}(q k^{T} / \\\\sqrt{C/h})\\\\) and \\\\(CA(x'^{l}) = A v\\\\), and multiple heads are used in the same way as in self-attention.

The attended output is added back to the projected CLS token with layer normalization applied to the concatenated input, and the result is projected back into the branch's own dimension. \\\\(y^{l}\_{cls} = f^{l}(x^{l}\_{cls}) + MCA(LN(\[f^{l}(x^{l}\_{cls}) \\\\\| x^{s}\_{patch}\]))\\\\), and \\\\(z^{l} = \[g^{l}(y^{l}\_{cls}) \\\\\| x^{l}\_{patch}\]\\\\), where f and g are the projection and back-projection functions.

No feed-forward network follows this cross-attention step, so the L-branch patch tokens pass through unchanged and only the CLS token carries the cross-scale information.

The CLS token already summarises the patches of its own branch, so letting it look at the patches of the other branch brings in information from a second scale. In the next encoder the same CLS token attends to its own patches again, which is how the cross-scale information reaches the patch tokens of its own branch.

## Alternatives to cross-attention

The simplest option, all-attention fusion, concatenates the tokens of both branches and applies self-attention to all of them, which costs quadratic time in the total token count. Class token fusion sums the two CLS tokens, passes the sum back through a projection to each branch, and keeps the patch tokens unchanged, so only one token is processed.

Pairwise fusion interpolates the patch tokens of the two branches to a common spatial size and fuses them position by position, while the CLS tokens are summed separately.

Cross-attention keeps the efficiency of class token fusion, since only one token per branch acts as the query, but it still lets each branch read the other branch's patch tokens. The later ablation checks whether this design choice gives better accuracy than the three simpler schemes on CrossViT-S.

## Training and evaluation setup

The main evaluation uses ImageNet1K, which has 1,000 classes and about 1.28 million training images, with top-1 accuracy on the 50,000-image validation set as the metric. The models follow the DeiT recipe, which trains a ViT on ImageNet alone with strong data augmentation and regularization, and the authors use DeiT's default hyperparameters.

Instance repetition is enabled only for CrossViT-18, because the authors found it did not help the smaller models.

At evaluation the shorter image side is resized to 256 and a 224 by 224 center crop is used, and some models were fine-tuned at 384 by 384 with bicubic resizing of the position embedding. A convolutional patch tokenizer replaces the linear projection in the variants marked with a dagger, and it is used as a hybrid option in the comparison tables.

## Gains over the DeiT baselines

When DeiT-Ti, DeiT-S and DeiT-B serve as the large branch, CrossViT improves top-1 accuracy by 1.2, 1.2 and 0.4 points respectively, which the authors take as evidence that cross-attention learns useful multi-scale features. CrossViT-Ti reaches 73.4 against 72.2 for DeiT-Ti, CrossViT-S reaches 81.0 against 79.8 for DeiT-S, and CrossViT-B reaches 82.2 against 81.8 for DeiT-B, with FLOPs rising from 4.6 G to 5.6 G for the S pair.

The architectural changes described in Table 1 add a further 0.3 to 0.5 points, at a small cost in FLOPs and parameters.

The convolutional patch tokenizer adds 3.2 points to CrossViT-9, rising from 73.9 to 77.1, and 0.8 points to CrossViT-15.

The efficiency cost is visible in throughput, where CrossViT-S runs at 690 images per second and DeiT-S at 966 images per second in the same table.

## Comparison with other transformers and CNNs

Against ViT-B at 384, CrossViT-18 with the convolutional tokenizer reaches 82.8 against 77.9, with 9.5 G against 17.6 G FLOPs, which is a 4.9 point difference in top-1 accuracy.

Against the CNN models in Table 4, CrossViT-15 reaches 81.5 at 640 images per second, faster than most of the listed CNNs except ResNet-101, which the authors note is slightly faster. At higher resolution, CrossViT-18 with the convolutional tokenizer at 480 reaches 84.1, and the authors describe the best CrossViT models as competitive with EfficientNet, while expecting neural architecture search to close the rest of the gap.

## Transfer to smaller datasets

Transfer is tested on five tasks, CIFAR10, CIFAR100, Pet, CropDiseases and ChestXRay8, where the first four are natural images and ChestXRay8 contains medical images. The whole pretrained model is fine-tuned for 1,000 epochs with batch size 768, learning rate 0.01, SGD, weight decay 0.0001 and the ImageNet1K augmentation.

CrossViT-18 scores 99.11 on CIFAR10, 91.36 on CIFAR100, 95.07 on Pet, 99.97 on CropDiseases and 55.94 on ChestXRay8. DeiT-S scores 99.15, 90.89, 94.93, 99.96 and 55.39 on the same tasks, and CrossViT-15 scores 99.00, 90.77, 94.55, 99.97 and 55.89. The authors describe their models as on par with the DeiT models on all five downstream tasks, although CrossViT-15 sits slightly below DeiT-S on CIFAR10 and CIFAR100.

## What the ablations isolate

Cross-attention is the only scheme in which the S-branch reaches useful accuracy on its own, at 47.2 against 68.1 for the L-branch, while the other schemes leave the S-branch near chance at 0.1 to 7.6. The authors attribute this to the L-branch dominating in the other schemes, so that cross-attention is the only scheme in which the two branches learn distinct features whose ensemble is the best result.

Changing the small patch from 12 to 8 gives 80.8 with 6.7 G FLOPs, below the 81.0 at 5.6 G for the 12 and 16 pair, because the token ratio of 4 times is harder to fuse than a ratio of 2 times. The authors read these results as showing that the L-branch carries most of the feature extraction, so a light S-branch is enough, and that extra fusion steps add cost without accuracy.

Removing the CLS tokens and averaging the patch tokens of one branch as the query gives 80.0%, about 1% below the 81.0% of CrossViT-S, which supports the CLS token as the branch summary. Using the T2T module in place of the linear patch projection in both branches of CrossViT-18 gives 83.0% top-1, which is 0.5% above CrossViT-18 at 82.5.

## Limitations

The fusion ablations are run only on CrossViT-S, so the relative order of the fusion schemes is shown for that one configuration. The comparison with EfficientNet uses the higher-resolution variants, and the authors state that the remaining gap is an open question that neural architecture search might close. Throughput numbers come from one GPU type and one batch size in the CNN table, and the comparison with other transformers uses accuracies from the models' original reports rather than re-training.

The transfer experiments fine-tune for 1,000 epochs on five tasks, and the paper does not report results on other downstream tasks. The transformer variants in the comparison were trained only on ImageNet1K, and the stated scope of the claims covers that setting.

## Paper info

- **Authors**: Chun-Fu Chen, Quanfu Fan, Rameswar Panda
- **Venue**: arXiv · Preprint
- **First published**: 2021-3-27
- **Added**: 2026-11-12
- **Updated**: 2021-8-22
- **Version**: v2
- **arXiv**: 2103.14899
- **Category**: cs.CV
- **Original paper terms**: [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2103.14899v2) · [PDF ↗](https://arxiv.org/pdf/2103.14899v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Chun-Fu Chen, Quanfu Fan, Rameswar Panda (2021). CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification. arXiv:2103.14899v2. https://arxiv.org/abs/2103.14899v2

**BibTeX**

```
@misc{chen2021crossvit,
  title = {{CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification}},
  author = {Chun-Fu Chen and Quanfu Fan and Rameswar Panda},
  year = {2021},
  eprint = {2103.14899},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.14899v2}
}
```

## Related papers

- [Transformers in Vision: A Survey](https://refivu.com/en/papers/5380a1d5-fae3-41ad-ab72-e650e9db12fe-transformers-in-vision-a-survey.md)
- [Learning Land-Surface Hydrology World Model from Satellite Observations](https://refivu.com/en/papers/5b7cd482-ff8e-468e-bde7-b24240a651d4-learning-land-surface-hydrology-world-model-from-satellite.md)
- [Learning Transferable Visual Models From Natural Language Supervision](https://refivu.com/en/papers/c2ad57ff-fd96-4ad1-af27-4195a16c557d-learning-transferable-visual-models-from-natural-language.md)
- [Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet](https://refivu.com/en/papers/55385708-c65a-43d7-b2e0-c4751a8d2757-tokens-to-token-vit-training-vision-transformers-from.md)
- [CvT: Introducing Convolutions to Vision Transformers](https://refivu.com/en/papers/4d0c84cf-05bb-4f74-822e-0b8fbc635203-cvt-introducing-convolutions-to-vision-transformers.md)
- [MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer](https://refivu.com/en/papers/c76255ba-9c87-4edc-80cc-28d59c4ccfc5-mobilevit-light-weight-general-purpose-and-mobile-friendly.md)

## Other paper commentary

- [Can Spatiotemporal 3D CNNs Retrace the History of 2D CNNs and ImageNet?](https://refivu.com/en/papers/ff09b689-9e24-41cf-a1f9-f6aba563b3f5-can-spatiotemporal-3d-cnns-retrace-the-history-of.md)
- [Segmenter: Transformer for Semantic Segmentation](https://refivu.com/en/papers/f33fa10d-9d05-48d0-9506-83f7da0f5f1e-segmenter-transformer-for-semantic-segmentation.md)
- [MultiResUNet : Rethinking the U-Net Architecture for Multimodal Biomedical Image Segmentation](https://refivu.com/en/papers/e99144f0-6aca-4598-b66e-67a4575f7fe4-multiresunet-rethinking-the-u-net-architecture-for.md)
- [MLP-Mixer: An all-MLP Architecture for Vision](https://refivu.com/en/papers/bf0a9095-e638-4ae5-bab6-5abf2b479763-mlp-mixer-an-all-mlp-architecture-for-vision.md)
- [SemanticKITTI: A Dataset for Semantic Scene Understanding of LiDAR Sequences](https://refivu.com/en/papers/304a0de8-6214-4d64-8649-0176464fb2d4-semantickitti-a-dataset-for-semantic-scene-understanding-of.md)
- [Real-world Anomaly Detection in Surveillance Videos](https://refivu.com/en/papers/dd2c7247-4d8f-4a7a-8400-f4e9c8e74dca-real-world-anomaly-detection-in-surveillance-videos.md)
- [On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima](https://refivu.com/en/papers/9954c18e-def9-48fe-bfea-2f52f4ed7acb-on-large-batch-training-for-deep-learning-generalization.md)
- [Principles alone cannot guarantee ethical AI](https://refivu.com/en/papers/0e47907c-e3eb-4d3b-9eb2-114a78e7ef9c-principles-alone-cannot-guarantee-ethical-ai.md)
- [KGAT: Knowledge Graph Attention Network for Recommendation](https://refivu.com/en/papers/c8788d47-0620-4271-bfbc-99d522ade86e-kgat-knowledge-graph-attention-network-for-recommendation.md)
- [Tensor Fusion Network for Multimodal Sentiment Analysis](https://refivu.com/en/papers/4fa58e5a-e78c-49d2-b78b-25f6eb2e5a71-tensor-fusion-network-for-multimodal-sentiment-analysis.md)
- [G-Eval: NLG Evaluation using GPT-4 with Better Human Alignment](https://refivu.com/en/papers/d14a3666-4caf-4371-83b0-d44fc50735f5-g-eval-nlg-evaluation-using-gpt-4-with.md)

## Terms in this paper

- [Top-1 accuracy](https://refivu.com/en/terms/653c0b9eaa58-top-1-accuracy)
- [transfer learning](https://refivu.com/en/terms/9c71d6928a00-transfer-learning)
- [FLOPs](https://refivu.com/en/terms/14c405888d5b-flops)
- [Vision Transformer](https://refivu.com/en/terms/143abf165d88-vision-transformer)
- [cross-attention](https://refivu.com/en/terms/83e3067f3ffa-cross-attention)
- [DeiT](https://refivu.com/en/terms/24b9f164881b-deit)
- [throughput](https://refivu.com/en/terms/f064ae564aec-throughput)
- [CLS token](https://refivu.com/en/terms/72d96a8cb8ef-cls-token)
- [feed-forward network](https://refivu.com/en/terms/f5454fe080e2-feed-forward-network)
- [ImageNet1K](https://refivu.com/en/terms/8cfcb134f1ea-imagenet1k)
- [multiheaded self-attention](https://refivu.com/en/terms/02f3bd8d8a1d-multiheaded-self-attention)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/a8519cc4-3678-45c7-b33a-b64e061e2edf-crossvit-cross-attention-multi-scale-vision-transformer-for)
