StyleSwin: Transformer-based GAN for High-resolution Image Generation

Bowen Zhang 0010, Shuyang Gu, Bo Zhang 0025, Jianmin Bao, Dong Chen, Fang Wen, Yong Wang, Baining Guo

Introduction

Generative Adversarial Networks (GANs) have long been dominated by convolutional architectures, particularly for high-resolution tasks. While Transformers have seen immense success in natural language processing and discriminative vision tasks, scaling them for high-fidelity image synthesis at 1024×1024 resolution has remained a significant challenge. StyleSwin addresses this gap by introducing a pure Transformer-based GAN capable of producing megapixel-scale images that rival state-of-the-art convolutional models like StyleGAN2.

High-resolution 1024x1024 face synthesis demonstrating fine detail and lack of artifacts.

The primary hurdles in scaling Transformers for generation include the quadratic computational complexity of self-attention, the lack of inherent spatial inductive biases, and the emergence of "blocking artifacts" when using window-based attention mechanisms to manage costs.

Methodology

StyleSwin leverages the Swin Transformer as its core backbone, utilizing local window-based attention to maintain linear computational complexity relative to image resolution. To adapt this architecture for high-quality synthesis, several key innovations were implemented:

  • Style-based Architecture: Latent codes are processed through a mapping network and injected into Transformer blocks via Adaptive Instance Normalization (AdaIN), mirroring the successful design of StyleGAN.
  • Double Attention: To expand the receptive field without significant overhead, StyleSwin employs "Double Attention," where attention heads are split between local and shifted window partitions simultaneously.
  • Sinusoidal Positional Encoding (SPE): Explicit positional information is added at every resolution scale to provide the global structural context that Transformers otherwise lack.
  • Wavelet Discriminator: To eliminate grid-like blocking artifacts, a novel discriminator operates in the wavelet domain. By identifying periodic spikes in the frequency spectrum, it effectively penalizes spatial discontinuities between attention windows.

Experimental Setup

The model was evaluated on several high-resolution benchmarks, focusing on both facial and architectural datasets:

  • FFHQ & CelebA-HQ: Human face datasets at 1024×1024 resolution.
  • LSUN Church & LSUN Car: Scene-based datasets at 256×256 resolution.

Results and Discussion

StyleSwin achieves state-of-the-art performance on high-resolution benchmarks. On CelebA-HQ 1024, it reached an FID of 4.43, surpassing StyleGAN2's 5.06. On FFHQ 1024, its performance (FID 5.07) is competitive with top-tier convolutional models.

Qualitative synthesis results across FFHQ (faces) and LSUN Church datasets.

Key Insights

  • Locality as an Inductive Bias: Restricting attention to local windows provides a beneficial bias similar to convolutions, aiding the learning of natural image regularities.
  • Spectral Awareness: The Wavelet Discriminator is crucial for visual quality, as it targets spectral discrepancies that are often invisible to standard spatial discriminators but cause noticeable artifacts.
  • Efficiency: StyleSwin is theoretically more efficient than StyleGAN2, requiring 50.9B FLOPs compared to 74.2B for 1024×1024 generation, despite having a larger parameter count.

Conclusion

StyleSwin demonstrates that pure Transformer architectures can excel at high-resolution image generation. While theoretical efficiency is high, current hardware optimizations for convolutions mean that StyleSwin's actual throughput (11 images/sec) still lags behind StyleGAN2 (40 images/sec). Future work focusing on optimized Transformer kernels and specialized regularization techniques for high-resolution synthesis will likely bridge this gap, potentially establishing Transformers as the new standard for generative modeling.

Summary updated

BibTeX
@inproceedings{zhang2021styleswin,
  author = {Bowen Zhang and Shuyang Gu and Bo Zhang and Jianmin Bao and Dong Chen and Fang Wen and Yong Wang and Baining Guo},
  title = {{StyleSwin: Transformer-based GAN for High-resolution Image Generation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2021},
  doi = {10.1109/cvpr52688.2022.01102},
}
Figure