Rewriting geometric rules of a GAN

Sheng-Yu Wang, David Bau, Jun-Yan Zhu

Abstract

Generative Adversarial Networks (GANs) are typically constrained by the geometric distributions of their training data. This paper discusses a novel framework for "rewriting" these internal rules using as few as five user-provided examples. By leveraging low-rank weight updates and style-mixing augmentation, the method enables significant out-of-distribution geometric transformations—such as altering the ear shape of animals or the structural lines of architecture—while preserving the model's original diversity in texture and lighting.

Introduction

Pre-trained generative models like StyleGAN excel at synthesizing high-fidelity images within their learned domain. However, modifying the fundamental geometry of generated objects (e.g., creating a cat with rabbit ears) remains a challenge. Traditional fine-tuning requires massive datasets, while latent space manipulation often struggles to produce drastic structural changes without degrading image quality or altering identity. This work addresses the problem of few-shot model editing: how to redefine a model's geometric "rules" with minimal supervision without causing catastrophic forgetting or mode collapse.

Methodology

The proposed approach shifts the focus from finding directions in latent space to directly optimizing the generator's weights ($\theta$).

1. User-Driven Warping

The process begins with a user selecting a small set of images (typically 5–10) from the pre-trained GAN. Using a warping interface with control points, the user reshapes these images to define the target geometry.

2. Weight Optimization and Style-Mixing

To align the model with the new geometry, the authors minimize the LPIPS (Learned Perceptual Image Patch Similarity) loss between the model's output and the warped targets. To prevent the model from simply memorizing the few training examples (overfitting), the researchers employ style-mixing augmentation. By fixing the "shape" latent codes to match the user edits but randomly varying the "texture" codes, the model is exposed to an infinite variety of appearances (colors, furs, backgrounds) that all must conform to the same new geometric rule.

3. Low-Rank, Localized Updates

The researchers found that geometric information is often localized within specific layers of the GAN (e.g., earlier layers for coarse shapes). By restricting updates to a single layer and enforcing a low-rank constraint (Rank-50), the method maintains high visual quality and drastically reduces the storage footprint of an edit to approximately 0.6 MB—a 100x reduction compared to full model checkpoints.

4. Model Composition

A significant finding is the linearity of these weight updates. Because edits are stored as weight offsets, multiple geometric rules (e.g., "long ears" and "large eyes") can be combined through simple linear addition of their respective weight matrices.

Evaluation and Results

The framework was tested across diverse domains using standard high-resolution datasets including AFHQv2 (animals), LSUN (churches, horses), Places (houses), and FFHQ (human faces).

  • Performance: The method outperforms existing few-shot adaptation techniques and text-to-image editing (like StyleGAN-NADA). Unlike text-based methods that often conflate geometry with texture, this approach isolates structural changes.
  • Real-World Utility: By projecting real photographs into the GAN's latent space, users can apply the rewritten geometric rules to actual images, effectively "warping" reality based on the edited model's new logic.
  • Efficiency: The low-rank updates allow for easy sharing and stacking of model "patches," making it feasible to distribute specific geometric edits as lightweight files.

Discussion and Limitations

Despite its success, the method faces certain constraints. GANs exhibit a strong internal symmetry bias, making it difficult to apply asymmetric edits (e.g., modifying only one ear). Additionally, the model struggles with topological changes, such as adding entirely new objects or textures that weren't present in the original distribution. Finally, in complex scenes like urban architecture, the consistency of the edit across all instances in a frame can vary.

Conclusion

Rewriting the weights of a GAN provides a powerful mechanism for customizing generative models. By treating geometric rules as additive weight offsets and using style-mixing to regularize the learning process, this method allows for precise, creative control over generative outputs with minimal data requirements. Future work may explore pre-computing warping bases to further reduce training time and automate the definition of complex warps.

Summary updated

BibTeX
@article{wang2022rewriting,
  author = {Sheng-Yu Wang and David Bau and Jun-Yan Zhu},
  title = {{Rewriting geometric rules of a GAN}},
  journal = {ACM Trans. Graphics},
  year = {2022},
  doi = {10.1145/3528223.3530065},
}
Figure