HyperInverter: Improving StyleGAN Inversion via Hypernetwork

Tan M. Dinh, Anh Tuan Tran, Rang Nguyen, Binh-Son Hua

TL;DR

HyperInverter introduces a purely encoder-based, two-phase framework for StyleGAN inversion that breaks the classic trade-off between reconstruction quality, editability, and inference speed. By first encoding images into the highly editable $\mathcal{W}$-space and then using hypernetworks to predict generator weight updates in a single forward pass, it achieves near-optimization-level quality at a fraction of the computational cost—running over 1000$\times$ faster than optimization-based alternatives.

What Problem Does This Paper Address?

Real-world image manipulation using Generative Adversarial Networks (GANs) relies heavily on GAN inversion—the process of mapping a real photograph into a pre-trained GAN's latent space so it can be faithfully reconstructed and edited.

However, existing inversion methods force researchers to choose two out of three critical requirements:

  1. High Reconstruction Quality: Accurately capturing fine details (e.g., wrinkles, background textures).
  2. Editability: The ability to modify attributes (like age or expression) without introducing artifacts.
  3. Fast Inference: Processing images quickly enough for interactive, real-time applications.

Optimization-based methods yield excellent reconstruction and editability but take minutes per image because they iteratively update latent codes or generator weights for every single input. Conversely, encoder-based methods are lightning-fast (feed-forward) but struggle to capture fine details or sacrifice editability by mapping to less regular spaces like $\mathcal{W}^+$. HyperInverter bridges this gap, delivering high fidelity and editability at real-time speeds.

Methods

HyperInverter splits the inversion process into two sequential, purely encoder-based phases:

Figure 2. Our method contains two sequential phases: (1) We first train an encoder E1 to encode the input image x to a content code w in W-space; w represents the main semantics of the image, therefore used in editing later. The output image of this phase is ˆxw. (2) We further regress the residual weights to update the generator to faithfully reconstruct the input details. First, we use another encoder E2 and a fusion operator to extract the appearance code h from the input image x and the initial image ˆxw, where L is the number of style layers of StyleGAN. Then, we employ a series of hypernetworks to embed the appearance code h to the generator G by predicting the residual weights ∆θ. The final reconstructed image ˆx is generated by G with updated weights ˆθ = θ + ∆θ and w content code from Phase I.
  • Phase I (From Image to Content Code): The input image is passed through a primary encoder ($E_1$) that maps it directly into StyleGAN’s native $\mathcal{W}$-space. This space is highly regular and ideal for downstream editing, but it inherently lacks the capacity to represent every fine detail of a specific real-world image.
  • Phase II (Generator Refinement via Hypernetworks): To recover the missing details without resorting to slow, per-image optimization, the authors introduce a second encoder ($E_2$). This encoder extracts and fuses features from both the original input image and the rough Phase I reconstruction to form an "appearance code." A series of hypernetworks then takes this appearance code and predicts residual weights ($\Delta\theta$) to directly update the convolutional layers of the pre-trained StyleGAN generator.

Because both phases rely entirely on feed-forward neural networks, the entire pipeline executes in a single forward pass during inference.

Datasets

The authors evaluated HyperInverter on two distinct and challenging domains:

  • Human Faces: Trained on the FFHQ dataset (70,000 high-quality face images) and evaluated on the official test split of CelebA-HQ (2,824 images) at $1024 \times 1024$ resolution.
  • Churches: Evaluated on the LSUN Church dataset ($126,227$ training images, $300$ test images) at $256 \times 256$ resolution to test performance on complex, unaligned outdoor scenes.

Key Insights and Ideas

  • Decoupling Structure and Detail: Instead of forcing a single latent code to represent both global semantics and pixel-perfect details (which ruins editability), HyperInverter delegates semantics to the $\mathcal{W}$-space and fine-grained details to the generator's weights.
  • Hypernetworks as Instant Fine-Tuning: State-of-the-art methods like PTI achieve high fidelity by fine-tuning the generator via backpropagation for every new image. HyperInverter effectively trains a meta-network to predict what those fine-tuned weights should be in milliseconds.
  • Layer-Specific Sensitivity: An analysis of the predicted residual weights revealed that weight modifications are highly concentrated in the highest-resolution convolutional layers (e.g., $1024 \times 1024$). This confirms the hypernetwork successfully targets fine-grained textures and details rather than altering global geometry.

Key Results

HyperInverter achieves an excellent balance on the quality-time trade-off curve:

Figure 1. Our end-to-end encoder-based method has more accu- rate reconstruction while having fast inference (toward the bottom left of each plot). As can be seen, our work outperform other encoder-based inversion methods (pSp [37], e4e [44], ReStyle [3]) significantly. Comparing with per-image optimization inversion technique [1], our method is on par of quality but 3000× faster. Only PTI [38] has reconstruction quality better than our work. However, PTI requires per-image generator fine-tuning during the inference phase, which took a long time, 1100× longer.
  • Speedup: With an inference time of roughly 0.09 seconds per image on a single NVIDIA Tesla V100 GPU, HyperInverter is 3000$\times$ faster than optimization-based SG2 $\mathcal{W}^+$ and 1100$\times$ faster than PTI.
  • Reconstruction Fidelity: It significantly outperforms existing encoder-based methods (pSp, e4e, ReStyle) across all standard metrics. On CelebA-HQ, HyperInverter achieved an LPIPS score of 0.1054 (lower is better), soundly beating e4e (0.1992) and approaching the quality of optimization methods.
  • Editability: Quantitative tests for age and pose manipulation showed that HyperInverter produces stronger, cleaner editing effects with fewer visual artifacts (such as distorted backgrounds or ghosting) than methods operating in $\mathcal{W}^+$ space.

Limitations and Future Work

Despite its strengths, HyperInverter still exhibits a slight performance gap when compared to the absolute best optimization-based methods (like PTI) on certain strict reconstruction metrics.

To close this remaining gap, the authors suggest several promising future directions:

  1. Integrating iterative refinement techniques into the encoder steps.
  2. Employing more sophisticated loss functions, such as a multi-layer identity loss.
  3. Extending the architecture to support the newer, alias-free StyleGAN3 backbone.

Summary updated

BibTeX
@misc{dinh2021hyperinverter,
  author = {Tan M. Dinh and Anh Tuan Tran and Rang Nguyen and Binh-Son Hua},
  title = {{HyperInverter: Improving StyleGAN Inversion via Hypernetwork}},
  year = {2021},
  eprint = {2112.00719},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.00719},
}
Figure