GAN Inversion: Editing Real Photos with Fake Image Generators
GAN Inversion finds the latent code "recipe" inside a pre-trained GAN that best recreates a real image. This lets you use a generator's powerful editing features on real photos for tasks like manipulation or restoration.
WHY IT EXISTS Pre-trained Generative Adversarial Networks (GANs) like StyleGAN are incredibly powerful at synthesizing and manipulating novel images from a random code. However, their power is confined to this generated world. GAN inversion was created to bridge this gap, allowing us to apply the rich editing capabilities of a GAN to an existing, real-world photograph.
THE MENTAL MODEL Think of a pre-trained GAN as a complex synthesizer that can create millions of images by adjusting its control knobs (the latent vector). GAN inversion is the process of seeing a photograph (the target image) and figuring out the exact knob settings required to reproduce it on that synthesizer. It effectively turns the generator into an editor for real images.
HOW IT WORKS At its core, GAN inversion is an optimization problem. Given a real image and a frozen, pre-trained generator, the goal is to find a latent code 'z' that, when fed into the generator G(z), produces an image as close as possible to the real one. This is usually achieved by iteratively updating the latent code 'z' using gradient descent to minimize a loss function (like pixel-wise difference or perceptual similarity) between the generated and target images.
WHEN TO USE IT Use GAN inversion when you want to edit real-world images using the semantic controls learned by a powerful generative model. This is key for applications like adding a smile to a portrait, changing hair color, de-aging a face, or performing high-quality image restoration by projecting a corrupted image into the "clean" image manifold learned by the GAN.
WHEN NOT TO USE IT Do not expect GAN inversion to work well for images that are very different from the GAN's original training data (out-of-distribution images). For example, trying to invert a photo of a car using a GAN trained only on human faces will produce poor results. There is also a fundamental trade-off: a latent code that perfectly reconstructs an image might not be easily editable, and a highly editable code might not produce a perfect reconstruction.
ONE CANONICAL EXAMPLE A user wants to edit a portrait. They use GAN inversion to find the latent code in a pre-trained StyleGAN model that best recreates the person's face. Once they have this code, they can manipulate it along a pre-discovered "smile" vector in the latent space. Feeding this new, modified code back into the generator produces a new version of the original portrait, now with a realistic smile.
Read the original → arxiv.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.