FFT-Based Dynamic Token Mixer for Vision

Yuki Tatsunami, Masato Taki

Abstract: Multi-head-self-attention (MHSA)-equipped models have achieved notable performance in computer vision. Their computational complexity is proportional to quadratic numbers of pixels in input feature maps, resulting in slow processing, especially when dealing with high-resolution images. New types of token-mixer are proposed as an alternative to MHSA to circumvent this problem: an FFT-based token-mixer involves global operations similar to MHSA but with lower computational complexity. However, despite its attractive properties, the FFT-based token-mixer has not been carefully examined in terms of its compatibility with the rapidly evolving MetaFormer architecture. Here, we propose a novel token-mixer called Dynamic Filter and novel image recognition models, DFFormer and CDFFormer, to close the gaps above. The results of image classification and downstream tasks, analysis, and visualization show that our models are helpful. Notably, their throughput and memory efficiency when dealing with high-resolution image recognition is remarkable. Our results indicate that Dynamic Filter is one of the token-mixer options that should be seriously considered.

Introduction

Vision Transformers (ViTs) have revolutionized computer vision, largely due to the global modeling capabilities of Multi-Head Self-Attention (MHSA). However, MHSA suffers from quadratic complexity relative to the number of input tokens. As image resolution increases, the computational cost and memory requirements grow exponentially, making standard Transformers prohibitively expensive for dense prediction tasks like semantic segmentation or medical imaging where high-resolution input is critical.

Existing alternatives, such as GFNet, utilize Fast Fourier Transforms (FFTs) to perform global operations with a more favorable $O(N \log N)$ complexity. However, these models typically rely on "static" filters—weights that are learned during training but remain fixed for every image during inference. This lacks the data-dependency inherent in attention mechanisms, where the model adjusts its focus based on specific image content. This research introduces the Dynamic Filter, a token mixer that bridges this gap by combining the efficiency of FFTs with the adaptive nature of self-attention.

Methods: The Dynamic Filter Architecture

The core contribution of this work is the Dynamic Filter (DF), which operates in the frequency domain to achieve global receptive fields efficiently. The process involves four key steps:

  1. FFT Transformation: The input feature map is transformed into the frequency domain using a 2D Discrete Fourier Transform.
  2. Dynamic Weighting: Unlike static FFT mixers, the model maintains a set of "basis filters." A lightweight MLP processes the input image to predict coefficients that linearly combine these bases into a unique, image-specific filter on the fly.
  3. Element-wise Multiplication: The frequency-domain input is multiplied by this dynamic filter. Mathematically, this corresponds to a circular convolution with a global kernel in the spatial domain.
  4. Inverse FFT: The result is transformed back to the spatial domain for subsequent processing.
Architecture of the Dynamic Filter Generator and the DFFormer Block.

These Dynamic Filters are integrated into the MetaFormer architecture to create two model variants: DFFormer, a pure model using Dynamic Filter blocks throughout, and CDFFormer, a hybrid model that utilizes convolutions in early stages to capture local textures and Dynamic Filters in later stages for global context.

Experimental Evaluation

The models were evaluated on standard benchmarks to assess classification performance and scalability:

  • ImageNet-1K: DFFormer-B36 achieved 84.8% top-1 accuracy, outperforming existing FFT-based and MLP-based models. The hybrid CDFFormer-B36 reached 85.0%.
  • ADE20K: For semantic segmentation, CDFFormer-M36 achieved 48.6 mIoU, a significant improvement over the PoolFormer baseline (42.4 mIoU), demonstrating its effectiveness for high-resolution dense prediction.

Key Insights and Analysis

A critical finding is that data-dependency is the essential missing ingredient for FFT-based models. By introducing dynamic filters, the authors closed the performance gap between FFT-based mixers and MHSA while maintaining superior efficiency.

Analysis of the learned filters reveals that while MHSA primarily acts as a low-pass filter (smoothing signals), the Dynamic Filter is more versatile. It can learn to act as a high-pass or band-pass filter depending on the layer depth. Furthermore, visualization shows that the Dynamic Filter learns more distinct, less redundant patterns compared to static models like GFNet.

Visualization of learned frequency filters across different layers of the model.

In terms of scalability, DFFormer's throughput and memory usage remain remarkably stable as resolution increases. While MHSA-based models see their performance plummet at resolutions like $1024 \times 1024$, the FFT-based approach maintains high efficiency, making it a viable candidate for large-scale vision tasks.

Conclusion and Future Work

The Dynamic Filter represents a powerful alternative to self-attention for high-resolution vision tasks. By combining global reach, $O(N \log N)$ complexity, and input-adaptive weights, DFFormer and CDFFormer achieve state-of-the-art results with significantly lower resource requirements.

Future research may explore more sophisticated methods for generating dynamic weights beyond linear combinations of basis filters. Additionally, extending the Dynamic Filter to other domains, such as object detection or video recognition, remains a promising direction for further improving the efficiency of global token mixing.

Summary updated

BibTeX
@inproceedings{tatsunami2024fft,
  author = {Yuki Tatsunami and Masato Taki},
  title = {{FFT-Based Dynamic Token Mixer for Vision}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2024},
  url = {https://openreview.net/forum?id=uzlNzyveqd},
}
Figure