Abstract
GAN inversion is a critical task for real-world image editing, yet it remains plagued by the "distortion-editability" trade-off. Traditional CNN-based encoders often struggle to balance high-fidelity reconstruction with the ability to manipulate semantic attributes. We present StylePrompter, a novel framework that leverages a hierarchical vision Transformer (Swin Transformer) to treat latent codes as tokens. By introducing a Style-driven Multi-scale Adaptive Refinement Transformer (SMART) block, StylePrompter achieves superior reconstruction quality while maintaining a highly disentangled and editable latent space. Our approach demonstrates state-of-the-art performance across multiple benchmarks, including FFHQ and CelebA-HQ, with significantly fewer parameters than competing methods.
Introduction
Generative Adversarial Networks (GANs), particularly the StyleGAN family, have revolutionized image synthesis. By manipulating latent codes, users can perform sophisticated semantic edits on generated images. However, applying these capabilities to real-world photos requires GAN inversion—the process of mapping a real image back into the GAN's latent space.
This process is historically difficult due to the distortion-editability trade-off. Mapping an image to a low-dimensional latent space ($W$) ensures high editability but results in poor reconstruction (high distortion). Conversely, mapping to high-dimensional feature spaces ($\mathcal{F}$ space) yields near-perfect replicas but often "breaks" the latent space, making semantic edits (like adding a smile or removing glasses) produce visual artifacts. StylePrompter addresses this by rethinking the encoder architecture and the refinement process.
Methodology
StylePrompter introduces two primary architectural innovations designed to navigate the latent space more effectively than traditional Convolutional Neural Networks (CNNs).
1. Transformer-based Encoder
StylePrompter replaces the standard CNN backbone with a Swin Transformer. In this framework, latent codes are treated as "latent tokens," analogous to prompts in Large Language Models (LLMs). These tokens interact with image "patch tokens" through self-attention mechanisms. This allows the model to capture global relationships across the image, learning how different attributes correlate with specific latent features more holistically than the local receptive fields of a CNN.
2. The SMART Block
The Style-driven Multi-scale Adaptive Refinement Transformer (SMART) block is a specialized cross-attention module. It uses the generator's intermediate style features as queries to retrieve missing identity information from the encoder’s multi-scale feature maps.
Unlike previous methods that utilized "hard" refinement—essentially overwriting GAN features with encoder features—SMART employs "soft" refinement. It uses two learnable weights, $\beta_1$ and $\beta_2$, to control the flow of information. $\beta_1$ modulates the addition of identity-preserving details, while $\beta_2$ allows the model to selectively ignore or subtract irrelevant background patterns. This residual approach "nudges" the GAN toward the correct identity without destroying the semantic logic of the underlying latent space.
Results and Discussion
Quantitative Performance
Evaluated on the CelebA-HQ benchmark, StylePrompter achieved a competitive $L_2$ score of 0.022 and an LPIPS of 0.089. Notably, it achieves these results with approximately 64M parameters, making it significantly more efficient than state-of-the-art competitors like HFGI (303M) or FeatureStyleEncoder (113M).
Qualitative Fidelity and Editability
StylePrompter excels in preserving fine-grained details such as skin texture and individual hair strands. A key strength is its performance in "minus" edits—tasks like removing eyeglasses or closing an open mouth. While other feature-space methods often produce "ghosting" artifacts during these operations, StylePrompter maintains structural integrity.
The "Oil Painting" Analogy
To understand the different GAN spaces, the authors propose a helpful mental model:
- $W$ Space (The Pigments): Represents the "what" of the image—the fundamental colors and materials.
- $S$ Space (The Brush): Represents the "how"—the stylistic application of those materials.
- $\mathcal{F}$ Space (The Canvas): Represents the "where"—the spatial positioning of features.
By focusing on the interaction between these spaces through attention, StylePrompter ensures that the "canvas" is refined without losing the flexibility of the "pigments."
Conclusion
StylePrompter demonstrates that attention-based architectures are uniquely suited for GAN inversion. By treating latent codes as tokens and employing soft refinement via the SMART block, the framework successfully mitigates the distortion-editability trade-off. While the model currently faces challenges with out-of-domain background details (such as specific text), future iterations involving progressive refinement through stacked SMART blocks promise to further bridge the gap between perfect reconstruction and seamless editability.
Summary updated