NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

SpectFormer: Frequency and Attention is what you need in a Vision Transformer

Badri N. Patro, Vinay P. Namboodiri, Vijay Srinivas Agneeswaran

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.

Comparison of SpectFormer with purely attention-based (DeiT) and purely spectral (GFNet) models, highlighting the hybrid block structure and complexity.

Architecture and Methodology

The core innovation of SpectFormer is its Stage Architecture. A model with $L$ total blocks is divided into two distinct phases:

  1. 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.
  2. 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.

Architectural comparison of DeiT, the Spectral Block, and the proposed SpectFormer Stage Architecture.

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

BibTeX
@inproceedings{patro2025spectformer,
  author = {Badri N. Patro and Vinay P. Namboodiri and Vijay Srinivas Agneeswaran},
  title = {{SpectFormer: Frequency and Attention is what you need in a Vision Transformer}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2025},
  doi = {10.1109/wacv61041.2025.00924},
}
Figure