liveBook · Manning

Perceptual loss

As explained in Build a Text-to-Image Generator (from Scratch)

A perceptual loss measures differences between images using features intended to reflect human visual similarity rather than only pixel-wise differences.

Perceptual loss measures visual similarity between generated and real images by comparing learned representations rather than only corresponding pixel values. It aims to reflect how similar images look to human observers, making it useful when pixel-wise agreement does not fully capture visual quality. section 11.4.2

LPIPS is a common perceptual loss. It extracts features with a pretrained deep network, such as VGG or AlexNet, and compares those features between two images. This representation-based comparison captures perceptual realism more effectively than raw-pixel differences alone. section 11.4.2

Within VQGAN, perceptual loss contributes to reconstruction quality alongside adversarial and quantization losses. The adversarial term encourages convincing images, while the quantization term keeps encoder outputs close to codebook vectors; perceptual loss preserves visual fidelity. section 11.4.2 section 11.6

VQGAN reconstruction

A VQGAN reconstructs an image after encoding it, assigning latent patches to codebook entries, and decoding the resulting discrete codes. LPIPS evaluates the reconstruction against the original through deep features, helping favor an image that looks right rather than one that merely matches pixels. section 11.4.2 section 11.0

Figure 11.6 VQGAN architecture and training process in which VQGAN combines a VQ-VAE generator with a discriminator in a GAN framework
A diagram of a fish

AI-generated content may be incorrect.

Trace how perceptual loss fits into VQGAN training alongside the generator, discriminator, reconstruction, and quantization components. section 11.4.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Defines representation-based comparison and names LPIPS features, but stops short of deriving its numerical implementation.
Examples
Uses LPIPS to compare VQGAN reconstructions with original images through pretrained VGG or AlexNet features.
What it assumes
Assumes familiarity with images and introduces its role alongside GANs, VQ-VAEs, codebooks, and reconstruction.
What you can do after
Evaluate image fidelity using learned visual features rather than relying only on pixel-wise differences.
How it connects
Connects image reconstruction with LPIPS, pretrained neural networks, VQGAN, GANs, VQ-VAEs, and quantization loss.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.