Conditional Positional Encodings for Vision Transformers

Xiangxiang Chu, Zhi Tian, Bo Zhang, Xinlong Wang, Chunhua Shen
2/22/2021
893 citations
cs.CVcs.AIcs.LG

Official code: Meituan-AutoML/CPVT (196 stars, last commit 2023-02-14).

Abstract

We propose a conditional positional encoding (CPE) scheme for vision Transformers. Unlike previous fixed or learnable positional encodings, which are pre-defined and independent of input tokens, CPE is dynamically generated and conditioned on the local neighborhood of the input tokens.

Show full abstract

As a result, CPE can easily generalize to the input sequences that are longer than what the model has ever seen during training. Besides, CPE can keep the desired translation-invariance in the image classification task, resulting in improved performance. We implement CPE with a simple Position Encoding Generator (PEG) to get seamlessly incorporated into the current Transformer framework. Built on PEG, we present Conditional Position encoding Vision Transformer (CPVT). We demonstrate that CPVT has visually similar attention maps compared to those with learned positional encodings and delivers outperforming results. Our code is available at https://github.com/Meituan-AutoML/CPVT .

View on arXivView PDF

Code Implementations(1)

1968Feb 20, 20213 years ago

Similar Papers

Cite this paper

@article{chu2021conditional,
  title  = {Conditional Positional Encodings for Vision Transformers},
  author = {Xiangxiang Chu and Zhi Tian and Bo Zhang and Xinlong Wang and Chunhua Shen},
  year   = {2021},
  eprint = {2102.10882},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2102.10882}
}

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/2102.10882.svg)](https://codeofpaper.com/paper/2102.10882)

Discussion