[Paper Review] Can Vision Transformers Perform Convolution?
This paper proves that a single Vision Transformer (ViT) layer with relative positional encoding and at least 9 attention heads can exactly express any convolution operation when using image patches as input. The authors propose a two-phase training pipeline that initializes ViT from a pre-trained CNN using this theoretical construction, significantly improving performance on low-data regimes without architectural changes.
Several recent studies have demonstrated that attention-based networks, such as Vision Transformer (ViT), can outperform Convolutional Neural Networks (CNNs) on several computer vision tasks without using convolutional layers. This naturally leads to the following questions: Can a self-attention layer of ViT express any convolution operation? In this work, we prove that a single ViT layer with image patches as the input can perform any convolution operation constructively, where the multi-head attention mechanism and the relative positional encoding play essential roles. We further provide a lower bound on the number of heads for Vision Transformers to express CNNs. Corresponding with our analysis, experimental results show that the construction in our proof can help inject convolutional bias into Transformers and significantly improve the performance of ViT in low data regimes.
Motivation & Objective
- To determine whether a Vision Transformer layer can exactly express any convolution operation when using image patches as input.
- To establish theoretical lower bounds on the number of attention heads required for a ViT to express convolution, comparing patch-input and pixel-input settings.
- To develop a practical training pipeline that injects convolutional inductive bias into ViTs to improve generalization in low-data regimes.
- To demonstrate that the expressive power limitation of ViTs on small datasets is not due to architecture, but rather generalization capacity.
Proposed method
- Constructively prove that a multi-head self-attention layer with 9 heads and relative positional encoding can simulate any K×K convolution on image patches.
- Derive a lower bound showing that 9 heads are both necessary and sufficient for patch-input ViTs to express convolution, while K² heads are needed for pixel-input ViTs.
- Propose a two-phase training pipeline: first initialize ViT weights using the theoretical construction to mimic a pre-trained CNN, then fine-tune on downstream data.
- Use relative positional encoding to encode spatial relationships between patches, enabling attention to aggregate features across patch boundaries for convolutional operations.
- Preserve the standard MHSA module without architectural modifications, ensuring compatibility with existing ViT frameworks.
- Empirically validate the method on CIFAR-100 and ImageNet, comparing performance against randomly initialized ViTs.
Experimental results
Research questions
- RQ1Can a single ViT layer with image patches as input express any convolution operation using multi-head attention and relative positional encoding?
- RQ2What is the minimum number of attention heads required for a ViT layer to exactly represent a K×K convolution, under patch-input and pixel-input settings?
- RQ3Can injecting convolutional inductive bias via theoretical initialization improve ViT performance in low-data regimes?
- RQ4Is the 9-head construction optimal in terms of head count for expressing convolution in patch-input ViTs?
Key findings
- A single ViT layer with 9 heads and relative positional encoding can exactly express any K×K convolution when input is image patches, proving the expressive power of ViT beyond local receptive fields.
- The theoretical construction shows that 9 heads are both necessary and sufficient for patch-input ViTs to express convolution, while K² heads are required for pixel-input ViTs, demonstrating superior head efficiency in patch-based architectures.
- The proposed two-phase training pipeline, which initializes ViT using the theoretical construction from a pre-trained CNN, significantly improves test accuracy on CIFAR-100 and ImageNet in low-data regimes.
- The method enhances training efficiency and optimization stability, outperforming models trained from random initialization, even without architectural modifications.
- Empirical results confirm that the performance gap between ViT and CNNs on small datasets is primarily due to generalization, not expressive capacity, when proper inductive bias is injected.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.