Abstract
Recently, vision transformers (ViTs) have achieved excellent performance on vision tasks by measuring the global self-attention among the image patches. Given $n$ patches, they will have quadratic complexity such as $\mathcal{O}(n^2)$ and the time cost is high when splitting the input image with a small granularity. Meanwhile, the pivotal information is often randomly gathered in a few regions of an input image, some tokens may not be helpful for the downstream tasks. To handle this problem, we introduce an anchor-based efficient vision transformer (AnchorFormer), which employs the anchor tokens to learn the pivotal information and accelerate the inference. Firstly, by estimating the bipartite attention between the anchors and tokens, the complexity will be reduced from $\mathcal{O}(n^2)$ to $\mathcal{O}(mn)$, where $m$ is an anchor number and $m < n$. Notably, by representing the anchors with the neurons in a neural layer, we can differentiably learn these anchors and approximate global self-attention through the Markov process. It avoids the burden caused by non-differentiable operations and further speeds up the approximate attention. Moreover, we extend the proposed model to three downstream tasks including classification, detection, and segmentation. Extensive experiments show the effectiveness of our AnchorFormer, e.g., achieving up to a 9.0% higher accuracy or 46.7% FLOPs reduction on ImageNet classification, 81.3% higher mAP on COCO detection under comparable FLOPs, as compared to the current baselines.
Introduction
Vision Transformers (ViTs) have set new benchmarks in computer vision by capturing long-range dependencies through self-attention. However, the standard self-attention mechanism scales quadratically ($\mathcal{O}(n^2)$) with the number of image patches $n$. This creates a significant computational bottleneck for high-resolution images or fine-grained feature maps.
Furthermore, standard ViTs treat all patches equally, even though "pivotal" information is often concentrated in specific regions. While window-based or sparse attention methods attempt to mitigate the complexity, they often sacrifice global connectivity or rely on non-differentiable selection mechanisms that can inadvertently discard important features.
Methods: Differentiable Anchor Attention
AnchorFormer introduces a set of $m$ anchor tokens ($m \ll n$) to bridge the gap between efficiency and global context. Instead of computing an $n \times n$ attention matrix, the model computes bipartite attention between $n$ tokens and $m$ anchors.
The core innovations include:
- Differentiable Anchors: Anchors are parameterized as weights in a neural layer, allowing the model to learn optimal anchor distributions through standard backpropagation. This ensures the anchors naturally focus on the most salient parts of the image.
- Markov Process Approximation: The model treats the bipartite attention as transition probabilities in a Markov process to approximate the global self-attention matrix.
- Linear Complexity: By rearranging the order of matrix multiplications (exploiting the associative property), AnchorFormer achieves a complexity of $\mathcal{O}(mn)$, effectively linear with respect to the number of input tokens.
Key Results
AnchorFormer was evaluated on ImageNet (classification), COCO (detection), and ADE210K (segmentation), consistently outperforming established baselines like DeiT, Swin, and PVT.
- ImageNet Classification: AnchorFormer-B achieves 86.62% top-1 accuracy. Compared to DeiT, it offers a 46.7% reduction in FLOPs while boosting accuracy by up to 9.0%.
- Object Detection: On the COCO dataset, AnchorFormer achieves up to an 81.3% relative improvement in mAP over baselines like YOLOv5 and EfficientDet under similar computational budgets.
- Semantic Segmentation: Using Semantic-FPN on ADE210K, AnchorFormer reduced FLOPs by 14.4% and improved mIoU by 2.3% over the Pyramid Vision Transformer (PVT).
Conclusion
AnchorFormer demonstrates that a small set of learned, differentiable anchors can effectively capture global image context while significantly reducing computational overhead. While currently limited by incompatibility with causal masking for autoregressive tasks, its performance in vision tasks establishes a new state-of-the-art for efficient transformer architectures.
Summary updated