liveBook · Manning

Chapter 10: Diffusion models for images

What you will learn in chapter 10 of Deep Learning with PyTorch, Second Edition

The introduction contrasts image generation with text generation while identifying their shared goal of learning data patterns to produce plausible new samples.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction contrasts image generation with text generation while identifying their shared goal of learning data patterns to produce plausible new samples.

Key terms: pixels, tokens, spatial dependencies, generative AI, probability distribution, training dataset, samples

10.1 History of VAEs and GANs

This section explains how VAEs and GANs generate images and places their popularity in the history leading up to diffusion models.

Key terms: VAE, recognition model, encoder, generative model, decoder, latent representation, GAN, generator, discriminator, binary classifier

10.2 Motivator for diffusion models

This section motivates diffusion models with text-to-image examples, from DALL-E’s commercial practicality to high-resolution images made by open-source variants.

Key terms: diffusion models, DALL-E, text descriptions, images and their corresponding captions, Stable Diffusion

10.3 Diffusion in detail

This section explains diffusion models as a controlled process that gradually adds noise to an image and a learned process that reverses it to restore image structure.

Key terms: forward diffusion process, noise, schedule, reverse diffusion process, reversible by design, structure

10.4 Setting up the data

The section prepares a visualizable dataset of 2D points for demonstrating image diffusion.

Key terms: 2D points, points_from_img, (x,y) coordinates, tensor, plot points

10.5 The forward process

This section explains how forward diffusion progressively turns a dataset of 2D points into noise, and how to sample its state at any timestep without simulating every preceding step.

Key terms: forward process, T, x0, xt, beta, noise schedule, torch.randn, normal distribution, closed-form equation, alpha values

10.6 Training

This section explains what the denoising network is trained to predict, why that prediction enables image generation, and how a simple network represents its inputs.

Key terms: noisy (diffused) data, timestep, predicted noise, SinusoidalEmbedding, sinusoidal positional embedding, coordinates, linear layers, ReLU activations

10.6.1 Loss

This section defines a noise-prediction loss for a diffusion model and describes how to train the model with it.

Key terms: mean squared error, predicted noise, actual noise, reverse process, timestep, loss, backpropagate, optimizer, Adam optimizer

10.7 Reversing diffusion (how to sample)

This section explains how a trained diffusion model generates an image by repeatedly denoising random points in reverse timestep order.

Key terms: reverse diffusion process, timestep, sample, denoising model, predicted noise, controlled reintroduction of noise, random 2D points, sample_timestep, PyTorch logo

10.8 Conclusion

The conclusion recaps why diffusion models became prominent and how adding noise, learning to predict it, and sampling over timesteps can generate images.

Key terms: VAEs, GANs, diffusion models, photorealism, diversity, forward diffusion process, noise, 2D points, PyTorch logo, feedforward neural network

10.9 Exercises

10.10 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: How transformers work Chapter 11: Using PyTorch to fight cancer →

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.