Skip to main content
QUICK REVIEW

[Paper Review] SP-ViT: Learning 2D Spatial Priors for Vision Transformers

Yuxuan Zhou, Wangmeng Xiang|arXiv (Cornell University)|Jun 15, 2022
Brain Tumor Detection and ClassificationNeuroscience7 citations
TL;DR

This paper proposes Spatial Prior–enhanced Self-Attention (SP-SA), a learnable attention mechanism that automatically discovers 2D spatial inductive biases in Vision Transformers by parameterizing spatial relation functions via neural networks. SP-ViT models using SP-SA achieve state-of-the-art 86.3% Top-1 accuracy on ImageNet-1K with 50% fewer parameters than prior SOTA models.

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. 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.

Motivation & Objective

  • To address the slow convergence and overfitting of Vision Transformers in low-data regimes due to lack of spatial inductive biases.
  • To develop a learnable alternative to hand-crafted convolutional inductive biases that can capture diverse spatial relationships beyond local receptive fields.
  • To enable Vision Transformers to maintain a global receptive field while learning complementary spatial priors through dynamic, data-driven attention mechanisms.
  • To improve model efficiency and accuracy by replacing fixed inductive biases with adaptive, neural-parameterized spatial relation functions.

Proposed method

  • SP-SA enhances vanilla self-attention by introducing a learnable spatial relation function that maps relative patch coordinates to attention scores, enabling dynamic focus on specific spatial relations.
  • The spatial relation function is parameterized by a multi-layer perceptron (MLP) and jointly optimized with the ViT during training, allowing the model to discover effective spatial priors autonomously.
  • Each attention head learns a unique spatial prior, enabling complementary modeling of local and non-local spatial dependencies across the network.
  • The method replaces fixed positional embeddings with learnable, non-linear spatial priors that adapt to input content and relative position simultaneously.
  • SP-ViT is built by replacing standard attention blocks in ViT with SP-SA blocks, maintaining architectural simplicity while enhancing inductive bias.
  • The model is trained on ImageNet-1K at 224×224 and fine-tuned at 384×384, with no extra data or pretraining on larger resolutions.

Experimental results

Research questions

  • RQ1Can learnable, non-linear spatial priors improve Vision Transformer performance by capturing diverse 2D spatial relationships beyond fixed local receptive fields?
  • RQ2Does jointly optimizing a neural spatial relation function with the ViT architecture lead to better generalization and faster convergence than fixed positional embeddings or hand-crafted biases?
  • RQ3Can unique spatial priors per attention head and layer outperform shared or single priors in modeling complementary spatial inductive biases?
  • RQ4To what extent can SP-ViT reduce model parameters while maintaining or improving accuracy compared to existing SOTA ViT models?

Key findings

  • SP-ViT-L achieves a new state-of-the-art 86.3% Top-1 accuracy on ImageNet-1K, outperforming prior SOTA models like CaiT-M-36.
  • SP-ViT-L reduces model parameters by nearly 50% (150M) compared to CaiT-M-36 (271M), demonstrating significant efficiency gains.
  • The model with unique spatial priors per head and layer achieves 83.6% Top-1 accuracy, outperforming settings with shared or single priors.
  • SP-SA significantly outperforms vanilla self-attention with 1D or 2D relative positional embeddings, proving the superiority of learnable, non-linear spatial priors.
  • The ablation study confirms that non-linear spatial relation functions are essential—linear or fixed-parameter alternatives yield inferior performance.
  • SP-SA surpasses hand-crafted methods like Positional Self-Attention and Local SA, showing that learnable priors can replace manual design with better results.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.