Abstract
Vision Transformers (ViTs) have revolutionized computer vision but remain surprisingly sensitive to small spatial translations. Unlike Convolutional Neural Networks (CNNs), standard ViTs lack shift equivariance, where a shift in the input image should result in a corresponding shift in the feature map. This paper introduces a novel approach to restore this property by implementing an adaptive polyphase anchoring algorithm and circular-padded depthwise convolutions. These modifications allow ViTs to achieve 100% consistency under shifts, effectively eliminating the significant accuracy drops observed when objects move slightly within a frame.
Introduction: The Fragility of Vision Transformers
In computer vision, shift equivariance is a fundamental principle: the identity and features of an object should remain consistent regardless of its position in the image. While CNNs possess an inherent inductive bias for this, ViTs are fragile. They partition images into fixed patches and apply coordinate-dependent positional encodings. Consequently, a single-pixel shift can cause the sampling grid to align differently with the object, disrupting the internal representations and leading to inconsistent predictions.
Even advanced architectures like Swin or Twins, which incorporate hierarchical structures, suffer from this lack of robustness. Research indicates that standard models can experience accuracy drops of up to 20% under "shift attacks"—adversarial-like small translations designed to find the model's breaking point.
Methodology: Restoring Equivariance
The researchers propose two primary architectural enhancements to ensure that every module in the network is shift-equivariant.
Polyphase Anchoring Algorithm
The core innovation is the polyphase anchoring algorithm. Standard downsampling operations, such as patch embeddings or strided convolutions, are "aliased" because they rely on a fixed grid. If the image shifts, the grid samples different pixels.
The proposed algorithm adaptively selects a "maximum polyphase"—the grid alignment with the highest $L_p$ norm—to serve as an anchor. The input is then circularly shifted so that this anchor always aligns with the top-left of the processing windows. This content-aware anchoring ensures that the downsampling process remains consistent relative to the image content, rather than the absolute coordinate system.
Circularly-Padded Depthwise Convolutions
To address the issues caused by fixed positional encodings, the authors replace them with depthwise convolutions using circular padding. Unlike absolute or relative positional embeddings, which are tied to specific grid coordinates, these convolutions learn spatial relationships that move naturally with the image content, maintaining equivariance throughout the transformer blocks.
Experimental Results
The models were rigorously evaluated on the ImageNet-1K dataset, focusing on classification consistency and robustness to translations.
Performance and Consistency
The "Poly" versions of ViT and Twins achieved a perfect 100% consistency score. In contrast, vanilla models typically range between 85% and 90% consistency. This means the modified models provide the exact same classification label for an image and any of its shifted versions.
Robustness to Shift Attacks
In a "worst-of-30" shift test—where the model is tested against the most damaging shift within a 30-pixel range—the standard Twins model's accuracy dropped from 80.57% to 62.40%. The Twins-poly version maintained its performance at 80.78%, demonstrating total immunity to such translations. Furthermore, the models showed enhanced robustness to other spatial perturbations, including random cropping and affine transformations.
Conclusion
By identifying subsampling layers as the primary source of non-equivariance in ViTs, this work provides a mathematically grounded framework for building spatially robust transformers. The proposed polyphase anchoring and circular-padded convolutions offer a "plug-and-play" solution that guarantees shift equivariance without relying on extensive data augmentation. While future work is needed to scale these methods to larger datasets and real-time applications, this research marks a significant step toward making Vision Transformers as reliable as the biological systems they aim to emulate.
Summary updated