Skip to main content
QUICK REVIEW

[Paper Review] Do We Really Need Explicit Position Encodings for Vision Transformers

Xiangxiang Chu, Bo Zhang|arXiv (Cornell University)|Feb 22, 2021
Advanced Image and Video Retrieval TechniquesComputer Science38 references90 citations
TL;DR

This paper proposes Conditional Position Encoding (PEG), a learnable, local neighborhood-based position encoding scheme that replaces fixed positional encodings in Vision Transformers. By generating position encodings conditionally from the spatial context of each token, PEG enables arbitrary input sequence lengths and achieves state-of-the-art performance on ImageNet classification, outperforming models with predefined positional encodings.

ABSTRACT

Almost all visual transformers such as ViT or DeiT rely on predefined positional encodings to incorporate the order of each input token. These encodings are often implemented as learnable fixed-dimension vectors or sinusoidal functions of different frequencies, which are not possible to accommodate variable-length input sequences. This inevitably limits a wider application of transformers in vision, where many tasks require changing the input size on-the-fly. In this paper, we propose to employ a conditional position encoding scheme, which is conditioned on the local neighborhood of the input token. It is effortlessly implemented as what we call Position Encoding Generator (PEG), which can be seamlessly incorporated into the current transformer framework. Our new model with PEG is named Conditional Position encoding Visual Transformer (CPVT) and can naturally process the input sequences of arbitrary length. We demonstrate that CPVT can result in visually similar attention maps and even better performance than those with predefined positional encodings. We obtain state-of-the-art results on the ImageNet classification task compared with visual Transformers to date. Our code will be made available at this https URL .

Motivation & Objective

  • To address the limitation of fixed positional encodings in Vision Transformers, which restrict sequence length adaptability.
  • To eliminate the need for predefined, fixed-dimension sinusoidal or learnable vectors in vision transformers.
  • To enable Vision Transformers to process variable-length input sequences naturally and efficiently.
  • To develop a position encoding mechanism that is context-aware and spatially conditioned on local image features.
  • To achieve state-of-the-art performance on ImageNet classification while maintaining flexibility in input size.

Proposed method

  • Proposes a Position Encoding Generator (PEG) that computes position encodings based on the local spatial neighborhood of each input token.
  • Uses a small convolutional network to generate position embeddings conditioned on the feature map around each token.
  • Integrates the generated position encodings directly into the self-attention mechanism of Vision Transformers.
  • Replaces standard learnable or sinusoidal positional encodings with the PEG-generated embeddings, enabling dynamic sequence length handling.
  • Trains the PEG module end-to-end with the rest of the transformer architecture.
  • Enables inference on arbitrary input sizes by relying on local context rather than fixed positional vectors.

Experimental results

Research questions

  • RQ1Can position encodings be generated dynamically from local image features instead of being predefined?
  • RQ2Does a context-dependent position encoding scheme outperform fixed positional encodings in Vision Transformers?
  • RQ3Can a transformer model with conditional position encodings handle variable-length input sequences without performance degradation?
  • RQ4Is it possible to achieve state-of-the-art accuracy on ImageNet without using fixed positional embeddings?
  • RQ5How do attention maps and model behavior compare between PEG and traditional positional encoding methods?

Key findings

  • The proposed CPVT model with PEG achieves state-of-the-art performance on the ImageNet classification benchmark, surpassing previous Vision Transformers.
  • CPVT produces visually similar attention maps to models with predefined positional encodings, indicating comparable feature localization.
  • The model with PEG maintains strong performance across varying input sizes, demonstrating flexibility in sequence length.
  • The conditional position encoding mechanism enables seamless processing of arbitrary-length input sequences, overcoming a key limitation of standard Vision Transformers.
  • The ablation study confirms that PEG is effective and generalizable, with consistent improvements over fixed positional encoding baselines.

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.