Abstract
Generative Adversarial Networks (GANs) have traditionally relied on Convolutional Neural Networks (CNNs). However, CNNs suffer from locality bias, limiting their ability to capture long-range dependencies and global structures. We present Styleformer, a novel GAN generator that replaces convolutional layers with a modified Transformer architecture. By introducing Attention Style Injection and leveraging low-rank attention mechanisms, Styleformer effectively captures global image structures. Our model achieves state-of-the-art results on datasets like CIFAR-10 and demonstrates superior performance on complex compositional scenes such as Cityscapes and CLEVR.
Introduction
Convolutional Neural Networks (CNNs) have been the standard for image generation due to their efficiency and inductive bias for local patterns. Despite their success, CNNs struggle with global coherence—for instance, maintaining symmetry in faces or logical layouts in complex street scenes—because of their limited receptive fields. While Transformers have excelled in natural language processing by modeling long-range dependencies, their application to high-resolution image generation is hindered by quadratic computational complexity and training instability. Styleformer addresses these challenges by adapting the Transformer architecture for generative tasks.
Methods
The Styleformer generator is built upon a modified Transformer encoder. A core innovation is Attention Style Injection, where style vectors modulate the generation process. Unlike standard StyleGAN, which modulates convolutional weights, Styleformer modulates features twice: before the Query and Key transformations to influence the attention map, and at the Value transformation to influence output features. A demodulation step is included to maintain activation stability.
To improve efficiency and stability, the architecture employs Pre-Layer Normalization and removes the standard Feed-Forward Network (FFN). To provide the model with diverse "kernels" similar to CNN channels, the number of attention heads is significantly increased (to 32 or more). For high-resolution tasks, Styleformer-L utilizes the Linformer mechanism for linear-time complexity, while Styleformer-C adopts a hybrid approach, using Transformers for coarse global structure and CNN blocks for fine-grained textures.
Key Results
Styleformer demonstrates competitive performance across multiple benchmarks. On CIFAR-10, it achieves an FID of 2.82, surpassing StyleGAN2-ADA (2.92). Its strength in modeling spatial relationships is particularly evident in the CLEVR dataset, where it improves FID from 16.05 (StyleGAN2) to 11.67.
The model also shows significant efficiency gains; Styleformer-L is 1.3x faster and uses 3x less memory than the standard variant on CelebA. Spectrum analysis confirms that image attention maps are naturally low-rank, justifying the use of Linformer for high-resolution synthesis.
Conclusion
Styleformer successfully bridges the gap between Transformers and GANs, proving that self-attention can replace or augment convolutions for high-quality image synthesis. By prioritizing global structure through Transformers and optionally refining textures with CNNs, Styleformer sets a new direction for generative modeling. Future work will focus on pure Transformer architectures for ultra-high-resolution images and addressing the ethical implications of high-fidelity synthesis.
Summary updated