liveBook · Manning

Chapter 17: Image generation

What you will learn in chapter 17 of Deep Learning with Python, Third Edition

The chapter introduces image generation as learning a latent visual space and sampling from it to create new pictures.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces image generation as learning a latent visual space and sampling from it to create new pictures.

Key terms: image generation, latent visual spaces, sampling

17.1 Deep learning for image generation

This section explains why the book focuses on images even though the techniques discussed can apply to other media.

Key terms: latent spaces, images, sound, music

17.1.1 Sampling from latent spaces of images

Explains how sampling from a learned image latent space generates new images, how text can guide that sampling, and why the results may be visually incoherent.

Key terms: latent space, generator, decoder, sampling, text-conditioning, text-to-image models, language-guided image generation, interpolating, coherence of generated images

17.1.2 Variational autoencoders

This section explains how variational autoencoders turn image reconstruction into a way to learn a continuous latent space suitable for generation and editing.

Key terms: autoencoder, encoder, decoder, code, latent space, VAE, z_mean, z_log_variance, latent normal distribution, stochasticity

17.1.3 Implementing a VAE with Keras

This section builds a Keras VAE for MNIST digits, explains its custom loss workflow, and uses its decoder to explore the learned latent space.

Key terms: encoder network, sampling layer, decoder network, z_mean, z_log_var, latent space, strides, max pooling, information location, reconstruct

17.2 Diffusion models

This section connects autoencoder denoising to diffusion models, explaining how repeated denoising can generate an image from pure noise.

Key terms: denoising, image super-resolution, hallucinating, diffusion models, reverse diffusion models, denoising autoencoder, pure noise

17.2.1 The Oxford Flowers dataset

This section introduces the Oxford Flowers dataset and explains how to load and resize its images for image generation without distorting them.

Key terms: Oxford Flowers dataset, image_dataset_from_directory(), crop_to_aspect_ratio, aspect ratio

17.2.2 A U-Net denoising autoencoder

This section describes a U-Net denoising model that predicts noise for repeated diffusion steps and uses matching downsampling and upsampling stages to preserve image detail.

Key terms: noise_rates, predicted noise mask, diffusion denoising process, U-Net, downsampling stage, middle stage, upsampling stage, widths, 1:1 mapping, concatenative residual connections

17.2.3 The concepts of diffusion time and diffusion schedule

Defines diffusion time for iterative image denoising and explains how a cosine diffusion schedule maps that time to noise and signal rates.

Key terms: diffusion process, denoising autoencoder, diffusion time, diffusion schedule, cosine schedule, diffusion_schedule(), diffusion_times, noise_rates, signal_rates

17.2.4 The training process

This section describes how a diffusion model prepares noisy images, predicts their noise masks, and trains the denoiser by comparing predicted noise with the noise added.

Key terms: image normalization layer, unit variance, zero mean, call(), diffusion times, diffusion schedule, noise rates, signal rates, noise masks, mean absolute error

17.2.5 The generation process

17.2.6 Visualizing results with a custom callback

The section explains why generated images should be inspected during training and how a custom callback can display them after each epoch.

Key terms: custom callback, generate() method, epoch

17.2.7 It’s go time!

The section puts the diffusion model into training on Oxford Flowers, explains two training-stabilization choices, and shows how generated images are monitored.

Key terms: AdamW, InverseTimeDecay, exponential moving average of model weights, Polyak averaging, VisualizationCallback, ModelCheckpoint, epochs

17.3 Text-to-image models

This section explains how text conditions a diffusion model to generate images, then introduces pretrained Stable Diffusion, negative prompts, and limits on output quality.

Key terms: text encoder, text_embeddings, denoising model, prompt, image pairs, negative prompt, positive_prompt, negative_prompt, denoiser, Stable Diffusion, KerasHub

17.3.1 Exploring the latent space of a text-to-image model

The section shows how interpolating between text-prompt embeddings can produce a visual morph between generated images, and explains why spherical interpolation is used.

Key terms: text encoder, text embeddings, smooth, low-dimensional manifold, interpolation, slerp, spherical linear interpolation, text manifold, generate(), denoise, positive prompt

17.4 Summary

Concepts explained in this chapter

← Chapter 16: Text generation Chapter 18: Best practices for the real world →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.