Introduction
Vision Transformers (ViTs) have set new standards in computer vision by capturing global dependencies through Multi-Headed Self-Attention (MHSA). However, MHSA suffers from quadratic computational complexity ($O(N^2)$) and often struggles to efficiently capture fine-grained, high-frequency local details like sharp edges. Conversely, spectral-based models like GFNet utilize Fourier transforms for efficient $O(N \log N)$ token mixing, excelling at capturing periodic information but lacking the flexible, non-periodic interaction capabilities of attention.
This paper introduces SpectFormer, a hybrid architecture that bridges this gap. By strategically combining spectral layers for early feature extraction with attention layers for deep global reasoning, SpectFormer achieves state-of-the-art performance on ImageNet-1K while maintaining computational efficiency.
Architecture and Methodology
The core innovation of SpectFormer is its Stage Architecture. A model with $L$ total blocks is divided into two distinct phases:
- Spectral Blocks ($\alpha$ blocks): Positioned at the beginning of the network, these blocks utilize a Spectral Gating Network (SGN). The SGN applies a Discrete Fourier Transform (DFT) to input tokens, multiplies them by learnable complex weights, and performs an Inverse DFT. This mechanism acts as a global circular convolution, efficiently extracting structural features like edges and lines.
- Attention Blocks ($L - \alpha$ blocks): Following the spectral blocks, standard MHSA layers model complex, long-range dependencies between the features extracted in the initial stage.
Empirical results suggest that for a 12-layer model, an optimal configuration uses $\alpha = 4$ spectral blocks followed by 8 attention blocks.
Key Insights
- Optimal Layer Ordering: The authors demonstrate that spectral layers are most effective at the start of the pipeline, serving as sophisticated, learnable edge detectors. Reversing this order leads to a significant drop in performance.
- Localized Learning: Visualization of learned filters reveals that SpectFormer’s spectral layers develop sharper, more localized filters than purely spectral models. This suggests that subsequent attention layers provide a training signal that helps early spectral layers learn more relevant features.
- Efficiency Gains: By replacing the initial third of the network with $O(N \log N)$ spectral layers, SpectFormer reduces the overall computational burden of the transformer architecture without sacrificing accuracy.
Experimental Results
SpectFormer was evaluated on ImageNet-1K, MS-COCO, and various transfer learning datasets:
- ImageNet-1K: SpectFormer-H-S (small) achieved 84.25% top-1 accuracy, outperforming GFNet-H and LiT by 2%. The large version (SpectFormer-H-L) reached 85.7%, a state-of-the-art mark for its size class.
- Downstream Tasks: On MS-COCO, SpectFormer-S outperformed Swin-T and PVTv2-B2 in object detection (AP) with comparable parameter counts.
- Transferability: The model showed robust performance across datasets like CIFAR-10/100 and Stanford Cars, often matching or exceeding specialized models like EfficientNet-B7.
Conclusion and Future Work
SpectFormer demonstrates that frequency-domain operations and self-attention are complementary. While the model is sensitive to the hyperparameter $\alpha$ and the real-world speedup of FFT can be limited by hardware optimization, it provides a powerful framework for efficient vision transformers. Future research may explore alternative spectral transforms, such as Wavelets, or adaptive methods for layer allocation.
Summary updated