liveBook · Manning

Objective function

As explained in Learn Generative AI with PyTorch

The objective value minimized during training, here composed of reconstruction loss and KL divergence for the VAE.

An objective function is the value a model minimizes during training. In a variational autoencoder (VAE), it combines reconstruction loss with KL divergence: one term rewards images that resemble the originals, while the other compares the encoder’s output with a standard normal distribution. section 7.3.2 section 2.2.1

The objective connects the training loop to the model’s desired behavior:

  • Feed a training image to the encoder and compress it into a probabilistic latent representation described by means and standard deviations. section 7.3.2
  • Sample an encoding, pass it to the decoder, and reconstruct the input image. section 7.3.2
  • Add pixel-level reconstruction loss to KL divergence, then backpropagate the total so the encoder and decoder parameters are updated. section 7.3.2
  • Interpret lower loss as progress toward both faithful reconstruction and more meaningful, generalizable latent representations. section 7.3.2

VAE face-image training

For a human face image with 196,608 pixels, the encoder produces a 100-value probabilistic representation. The decoder reconstructs the face, and training minimizes the sum of reconstruction loss and KL divergence. Afterward, the decoder can reconstruct encoded faces or generate new faces from randomly drawn latent encodings. section 7.3.2

Figure 7.6 The architecture of a VAE and the steps to train one to generate human face images. A VAE consists of an encoder (middle upper left) and a decoder (middle bottom right). In each iteration of training, human face images are fed to the encoder (step 1). The encoder compresses the images to probabilistic points in the latent space (step 2; since we assume normal distributions, each probability point is characterized by a vector of means and a vector of standard deviations). We then sample encodings from the distribution and present them to the decoder. The decoder takes sampled encodings (step 3) and reconstructs images (step 4). The VAE adjusts its parameters to minimize the sum of reconstruction loss and the KL divergence. The KL divergence measures the difference between the encoder’s output and a standard normal distribution.

Trace the encoder, latent distribution, sampling step, decoder, reconstruction, and combined objective in the VAE training diagram. section 7.3.2

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains the objective’s two terms and its backpropagation role, but does not derive their equations.
Examples
Uses reconstructed human faces, 196,608-pixel inputs, 100-value latent vectors, and randomly sampled encodings for novel images.
What it assumes
Assumes familiarity with neural-network training, encoders, decoders, latent representations, backpropagation, and probability distributions.
What you can do after
Apply it via a VAE training loop that computes combined loss and updates encoder and decoder parameters.
How it connects
Connects loss functions, optimization, variational autoencoders, reconstruction loss, KL divergence, latent space, encoders, and decoders.

Also explained in

Compare how 30 books explain objective function →

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.