Skip to main content
QUICK REVIEW

[Paper Review] Conditional Positional Encodings for Vision Transformers

Xiangxiang Chu, Zhi Tian|arXiv (Cornell University)|Feb 22, 2021
Advanced Neural Network ApplicationsComputer Science28 references404 citations
TL;DR

The paper introduces conditional positional encodings generated by a Position Encoding Generator (PEG) that are conditioned on local image neighborhoods, enabling CPVT to generalize to longer inputs and improve translation-equivalence and overall performance over fixed or learnable absolute encodings.

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

Motivation & Objective

  • Motivate and address limitations of fixed/learnable absolute positional encodings in vision transformers.
  • Propose a dynamic, input-conditioned positional encoding scheme (CPE) using PEG.
  • Build Conditional Position encoding Vision Transformer (CPVT) and demonstrate improved performance and generalization.
  • Show that CPE preserves translation equivalence and scales to higher input resolutions and downstream tasks.

Proposed method

  • Introduce Positional Encoding Generator (PEG) that conditions on local 2-D neighborhoods of input tokens.
  • Implement PEG as a 2-D convolution with kernel k and appropriate padding to produce E^{B×H×W×C} encodings.
  • Incorporate CPE into Vision Transformers following ViT/DeiT design to form CPVT, including CPVT-Ti, CPVT-S, and CPVT-B variants.
  • Explore CPVT-GAP, replacing the class token with global average pooling for translation-invariant classification.
  • Experimentally evaluate generalization to higher resolutions and compare with learnable absolute encodings and relative encodings.
  • Demonstrate PEG’s low parameter and FLOP overheads while achieving superior accuracy.

Experimental results

Research questions

  • RQ1Can conditional positional encodings conditioned on local neighborhoods improve vision transformer performance over fixed or learnable absolute encodings?
  • RQ2Do CPVT models generalize to longer input sequences and maintain translation-equivariant behavior?
  • RQ3How does CPVT with PEG perform at different model scales and resolutions, including with GAP vs class tokens?
  • RQ4What is the parameter/compute overhead of PEG relative to standard positional encodings?
  • RQ5Can CPVT improve pyramid transformer architectures and downstream tasks like segmentation and detection?

Key findings

  • CPVT outperforms previous vision transformers with fixed or learnable absolute positional encodings on ImageNet top-1 accuracy.
  • PEG introduces minimal parameter overhead (e.g., 1,728 parameters for CPVT-Ti with k=3, l=1) and negligible FLOPs impact.
  • CPVT enables direct generalization to higher input resolutions (e.g., 384×384 improves CPVT-Ti to 74.2% from 73.4% at 224×224).
  • CPVT-GAP further boosts performance, achieving state-of-the-art among vision transformers in their experiments (e.g., CPVT-Ti-GAP 74.9% top-1 with GAP).
  • PEG positioned within early encoder blocks yields strong performance, with 0–5 PEG placement often maximizing results.
  • CPVT demonstrates translation-equivariance advantages and better performance across pyramid architectures like PVT and Swin when using PEG.

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.