SP-ViT: Learning 2D Spatial Priors for Vision Transformers

Yuxuan Zhou, Wangmeng Xiang, Chao Li, Biao Wang, Xihan Wei +3 more
6/15/2022
cs.CV
transformer-attention

Official code: ZhouYuxuanYX/SP-ViT-Learning-2D-Spatial-Priors-for-Vision-Transformers (14 stars, Python, Apache-2.0, last commit 2023-03-27).

Abstract

Recently, transformers have shown great potential in image classification and established state-of-the-art results on the ImageNet benchmark. However, compared to CNNs, transformers converge slowly and are prone to overfitting in low-data regimes due to the lack of spatial inductive biases.

Show full abstract

Such spatial inductive biases can be especially beneficial since the 2D structure of an input image is not well preserved in transformers. In this work, we present Spatial Prior-enhanced Self-Attention (SP-SA), a novel variant of vanilla Self-Attention (SA) tailored for vision transformers. Spatial Priors (SPs) are our proposed family of inductive biases that highlight certain groups of spatial relations. Unlike convolutional inductive biases, which are forced to focus exclusively on hard-coded local regions, our proposed SPs are learned by the model itself and take a variety of spatial relations into account. Specifically, the attention score is calculated with emphasis on certain kinds of spatial relations at each head, and such learned spatial foci can be complementary to each other. Based on SP-SA we propose the SP-ViT family, which consistently outperforms other ViT models with similar GFlops or parameters. Our largest model SP-ViT-L achieves a record-breaking 86.3% Top-1 accuracy with a reduction in the number of parameters by almost 50% compared to previous state-of-the-art model (150M for SP-ViT-L vs 271M for CaiT-M-36) among all ImageNet-1K models trained on 224x224 and fine-tuned on 384x384 resolution w/o extra data.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

This is the official implementation of our BMVC 2022 paper "SP-ViT: Learning 2D Spatial Priors for Vision Transformers"

140Python, ShellOct 6, 20223 years agoApache-2.0
ade20kimage-classificationimagenetsemantic-segmentationtransformer+1 more

Similar Papers

Cite this paper

@article{zhou2022spvit,
  title  = {SP-ViT: Learning 2D Spatial Priors for Vision Transformers},
  author = {Yuxuan Zhou and Wangmeng Xiang and Chao Li and Biao Wang and Xihan Wei and Lei Zhang and Margret Keuper and Xiansheng Hua},
  year   = {2022},
  eprint = {2206.07662},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2206.07662}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2206.07662.svg)](https://codeofpaper.com/paper/2206.07662)

Discussion