Introduction
Generative Adversarial Networks (GANs), particularly StyleGAN, have revolutionized image synthesis. However, applying these models to real-world image editing requires GAN inversion—the process of mapping a physical image into the GAN’s latent space ($W+$). This process faces a persistent "distortion-editability" trade-off: optimizing for perfect reconstruction often pushes latent codes into regions of the manifold where semantic editing is impossible. Conversely, constraining codes to "editable" regions typically results in a loss of fine-grained detail. The Style Transformer addresses this by leveraging a multi-stage transformer architecture to bridge the gap between high-fidelity reconstruction and flexible attribute manipulation.
Architecture: Bridging the Gap with Attention
The core innovation of this work is the replacement of traditional convolutional mapping networks with a Transformer-based encoder. This approach treats the 18 distinct 512-dimensional latent codes required by StyleGAN as "query tokens."
Multi-Scale Feature Injection
A CNN-based backbone extracts multi-scale features from the input image, which serve as the "keys" and "values" for the transformer blocks. By using Cross-Attention, the model allows each latent code to selectively attend to specific spatial regions and features in the source image, effectively "picking" the necessary information for high-fidelity reconstruction.
Inter-code Relationships and Editing
To maintain the integrity of the latent representation, the model employs Self-Attention between the 18 query tokens. This ensures that the latent codes remain cohesive and do not diverge into un-editable regions of the $W+$ space. Beyond inversion, the framework supports two sophisticated editing paradigms:
- Label-based Editing: Utilizing pre-trained classifiers to identify non-linear editing directions, refined by a Hessian-based approach for image-specific paths.
- Reference-based Editing: A dedicated module facilitates attribute transfer by routing specific features from a reference image to the source latent code.
Experimental Results
The Style Transformer was evaluated on high-resolution benchmarks including FFHQ, CelebA-HQ, and LSUN Cars. It consistently outperformed state-of-the-art encoders like pSp and e4e across key metrics:
- Fidelity: The model achieved a Mean Squared Error (MSE) of 0.036 on the face domain, surpassing pSp (0.037).
- Distribution Quality: FID scores improved significantly to 28.31 (compared to 31.52 for pSp), indicating that inverted images more closely resemble genuine StyleGAN samples.
- Efficiency: The architecture is remarkably lightweight, utilizing only 40.6M parameters—an 85% reduction compared to pSp's 267.3M parameters.
Conclusion
The Style Transformer demonstrates that attention mechanisms provide a superior bridge for GAN inversion compared to standard convolutional encoders. By balancing spatial detail extraction with latent space constraints, it effectively resolves the distortion-editability trade-off. While the model currently faces challenges with extreme out-of-domain images and the computational overhead of multi-head attention, it sets a new standard for efficient, high-fidelity image editing.
Summary updated