liveBook · Manning

Reconstruction loss

As explained in Learn Generative AI with PyTorch

The loss term that measures pixel-level mismatch between an input image and its reconstruction in a VAE.

Reconstruction loss measures the pixel-level mismatch between an input image and its reconstruction. Training adjusts the encoder and decoder to minimize this difference, bringing reconstructed images closer to their originals. section 7.2.2 section 7.0

For an autoencoder, reconstruction loss is the main objective. A VAE adds KL divergence, which regularizes the latent distribution toward a standard normal while reconstruction loss preserves input detail. section 7.3.1 section 7.3.2

A typical image-reconstruction training step proceeds as follows:

  • Feed a batch of original images through the encoder and decoder. section 7.2.2
  • Compare each reconstructed pixel with the corresponding original pixel, square the differences, and average them to obtain mean squared error. section 7.2.2
  • Backpropagate the loss and update model parameters with Adam. section 7.2.2

Handwritten-digit autoencoder

A 28×28 grayscale digit is flattened into 784 values, compressed to a 20-value representation, and decoded back into 784 pixels. Before training, reconstructions appear as noise; minimizing pixel-wise squared error makes them increasingly resemble the originals. section 7.0

How Learn Generative AI with PyTorch covers it

How deep it goes
Defines pixel-wise mean squared error and demonstrates its training-loop implementation, stopping short of alternative reconstruction metrics.
Examples
Uses handwritten-digit reconstructions and human-face reconstructions to compare inputs with decoder outputs.
What you can do after
Apply it via PyTorch by calculating reconstruction error, backpropagating it, and inspecting reconstructed images.
How it connects
Links autoencoders, variational autoencoders, decoders, latent space, KL divergence, and Adam optimization.

Also explained in

Compare how 10 books explain reconstruction loss →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.