liveBook · Manning

Diffusion model

As explained in Deep Learning with Python, Third Edition

A diffusion-based generative model that starts from noise and iteratively denoises it into an image.

A diffusion model generates an image by starting with pure noise and removing a little noise at each step. Think of it as a denoising autoencoder used repeatedly: one pass makes a small improvement; the full loop can turn noise into a new image. “Reverse diffusion” is the more precise name for this direction, because diffusion itself means gradually adding noise. section 17.2

Figure 17.7 Reverse diffusion: turning pure noise into an image via repeated denoising
diffusion

Follow the sequence from pure noise to a recognizable image; the intermediate images make the repeated-denoising idea concrete. section 17.2

For a concrete example, an unconditioned model trained on the Oxford Flowers dataset generates new flower images without a text prompt. Its denoiser runs at successive diffusion times. Here, time 1 marks the noisy start of generation, while time 0 marks an image that is almost entirely signal. section 17.2.3 section 17.2.7

Three practical pieces organize the loop:

  • Denoiser: remove a small amount of noise from the current image, then repeat. section 17.2
  • Diffusion time: identify the current step, from the noisy start toward the finished image. section 17.2.3
  • Diffusion schedule: map time to noise and signal rates. The worked implementation uses cosine and sine so the squared rates sum to 1. section 17.2.3

In the flower implementation, training uses Keras with AdamW, learning-rate decay, and an exponential moving average of weights to help stabilize training. Generated images are plotted after each epoch and model weights are checkpointed. This is a build-it-yourself route for unconditioned image generation; realistic results can improve with longer training. section 17.2.7 section 17.1.1

To guide the result with words, encode a prompt as a text embedding and give it to the denoiser alongside the noisy image. Training on prompt–image pairs then makes it possible to start from noise and generate an image for a new prompt. Training a strong text-to-image model from scratch is expensive, so a practical alternative is the pretrained Stable Diffusion 3 model through KerasHub’s TextToImage task. Its generation call also accepts a negative prompt and a chosen number of diffusion steps. section 17.3

Rule of thumb: use diffusion when realistic generated images are the goal; use a pretrained text-to-image model when prompt control matters more than building the model yourself. Treat the output as generated imagery, not reliable evidence: denoising-based image enhancement can hallucinate details. section 17.4 section 17.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Works through diffusion time, a cosine schedule, and flower-model training, but defers training a strong text-to-image model from scratch.
Examples
Uses generated Oxford Flowers images and a pretrained Stable Diffusion 3 prompt, with negative prompts and step counts as controls.
What it assumes
Introduces the denoising loop and diffusion schedule directly, while using Keras model-training code for the worked implementation.
What you can do after
Build it from scratch for unconditioned flowers, or apply it via KerasHub’s pretrained TextToImage task for prompt-guided images.
How it connects
Connects denoising autoencoders, diffusion schedules, latent image spaces, text embeddings, and text-to-image generation.

Also explained in

Compare how 10 books explain diffusion model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.