Overview

7 Generate high-resolution images with diffusion models

This chapter moves from basic diffusion on small grayscale images to producing vivid, high‑resolution color images efficiently and with greater control. It introduces two pillars that underpin modern text‑to‑image systems: a deeper U‑Net augmented with attention to scale modeling capacity, and the DDIM noise scheduler to accelerate sampling without sacrificing visual quality. It also highlights how the initial noise seed governs image outcomes and shows how interpolating between seeds yields smooth, controllable transitions—skills that prepare you for latent diffusion and Stable Diffusion later in the book.

On the modeling side, the denoising U‑Net is expanded with more downsampling and upsampling blocks, richer skip connections, and SDPA attention placed in both encoder and decoder to prioritize salient spatial features amid growing depth and redundancy. Time information is injected via sinusoidal embeddings, and forward diffusion is performed with DDIM to create training pairs of clean and noisy images. The model is trained on the Oxford 102 Flowers dataset by predicting the added noise at randomly chosen timesteps, optimized with AdamW and a cosine learning‑rate schedule, enabling it to reconstruct clean images from noise while retaining high‑frequency detail.

For inference, DDIM’s deterministic, non‑Markovian schedule enables high‑quality samples in far fewer steps than DDPM, making generation practical at higher resolutions. Beyond single images, the chapter demonstrates seed control and noise interpolation: blending two initial noise tensors produces sequences that morph smoothly between subjects, supporting controlled image synthesis and creative effects like transitions and animations. Together, attention‑enhanced U‑Nets, efficient DDIM sampling, and noise interpolation substantially elevate quality, speed, and controllability, laying the groundwork for text‑conditioned models explored next.

Eight steps for building a text-to-image generator from scratch. In this chapter, you will focus on mastering steps 3 and 4: enhancing the U-Net architecture with attention and leveraging advanced noise scheduling with DDIM. By incorporating attention into a deeper U-Net, you empower your diffusion models to generate highly detailed images that can accurately match text prompts in future chapters.
The architecture of the denoising U-Net model to generate high-resolution flower images. The U-Net is characterized by its symmetric U-shape, with the contracting path on the left, and the expansive path on the right, connected by the bottleneck block at the bottom. The model takes noisy images as inputs and predicts the noise in the images.
How image interpolation works in diffusion models. Initial noise tensor A (top left) leads to final output A (top right), while Initial noise tensor B (bottom left) leads to final output B (bottom right). We create an interpolated noise tensor (middle left) by averaging initial noise tensors A and B. We then feed this interpolated noise tensor into the trained denoising U-Net model to obtain an interpolated output image (middle right), which shows the characteristics of both final images A and B.
Sample images from the Oxford 102 Flower dataset, which contains roughly 8000 flower images. We use this dataset to train the denoising U-Net model.
The forward diffusion process using the DDIM noise scheduler. The four images in the leftmost column are clean images from the training dataset. We gradually add noise to the images. The second column shows the images after 200 time steps. The third column shows the noisy images after 400 time steps. The last column shows the images after 1000 time steps, when images are converted to pure random noise.
Ten flower images generated by the trained denoising U-Net model. We feed ten random noise tensors to the trained U-Net and use 50 inference steps to gradually remove noise from the noisy images. The ten images in this figure look all different due to the different initial noise tensors used.
Interpolated flower images. With the random state set to 100, we select the 2nd and 8th initial noise tensors to generate ten interpolated noise tensors by applying varying weightings to the originals. These interpolated tensors are then passed through the trained denoising U-Net, producing a series of ten flower images that smoothly transition from one to the other.
Three sets of interpolated flower images. Using a fixed random state of 100, we generate three pairs of initial noise tensors. Interpolated noise tensors are then created by blending the original tensors with varying weightings. Interpolated noise tensors are fed to the trained U-Net model to generate interpolated images. In each row, the images gradually transition from the leftmost to the rightmost image, illustrating smooth interpolation.

Summary

  • The denoising diffusion probabilistic models (DDPM) we studied in previous chapters use a randomized process and follow a Markovian process, meaning each step depends only on the immediate previous step. In contrast, a denoising diffusion implicit model (DDIM) takes a more direct and predictable approach. It uses a deterministic, non-Markovian process, allowing it to generate images in fewer steps without sacrificing quality.
  • While a simple U-Net may be adequate for generating grayscale images due to the reduced complexity, generating high-definition color images requires a more sophisticated architecture to handle the increased dimensionality and capture complex spatial and color relationships.
  • The advanced U-Net architecture in this chapter improves the model's ability to reconstruct fine details during denoising. However, adding more contracting and expansive blocks can lead to redundant feature extractions, making it challenging to identify the most relevant features. To mitigate this issue, the scaled dot product attention (SDPA) mechanism is incorporated, allowing the model to focus on significant features while filtering out the less important ones.
  • Once the denoising model is trained, we can generate high-resolution images by inputting an initial noise tensor into the U-Net. This noise tensor serves as a starting point that the model gradually refines into a clear and detailed image. Because the final image is influenced by the specific noise tensor used, different initial noise tensors will yield different results.
  • If we start with two different initial noise tensors, we can generate an interpolated tensor by taking a weighted average of them. Feeding this interpolated tensor into the trained denoising U-Net produces an image that blends the characteristics of the two images generated from the original noise tensors.
  • By varying the weights assigned to the two original noise tensors, we can create a series of interpolated initial noise tensors. Feeding these tensors into the trained denoising U-Net model generates a sequence of interpolated final images, displaying a smooth transition between the two original images.

FAQ

What is DDIM, and how is it different from DDPM?DDIM uses a deterministic, non-Markovian reverse process that can sample high-quality images in far fewer steps than DDPM. With eta set to 0, sampling is fully deterministic and reproducible; with eta greater than 0, it introduces controlled randomness for more diverse outputs, while remaining more efficient than DDPM.
Why add an attention mechanism to the U-Net, and where is it applied?As the U-Net grows deeper for higher resolutions, skip connections can propagate redundant features. Attention helps the model focus on the most informative spatial regions. Scaled dot-product attention is inserted in both the downsampling and upsampling paths, operating over flattened pixel sequences to capture long-range dependencies.
How does the initial noise tensor influence the generated image?Each unique noise tensor corresponds to a different output image. Fixing the random seed reproduces the same noise and the same result. Interpolating between two noise tensors produces a smooth visual transition between their corresponding images, useful for controlled generation and animation.
What does the eta parameter control during DDIM sampling?Eta governs the amount of noise reintroduced at each reverse step. Eta = 0 makes sampling deterministic (repeatable results). Increasing eta adds stochasticity, which can boost sample diversity at the cost of slightly less determinism or consistency.
How do we scale diffusion models to higher-resolution images?We deepen the U-Net with more down/up blocks and a richer bottleneck, and we add attention to better model global context. This improves detail and coherence at higher resolutions, with the trade-off of increased memory and compute requirements.
Why use sinusoidal timestep embeddings instead of learned embeddings?Fixed sinusoidal embeddings reduce the number of learnable parameters and often stabilize training in large models, while still providing smooth, multi-scale representations of diffusion timesteps.
What data and augmentations are used for training in this chapter?The chapter uses the Oxford 102 Flowers dataset. Images are resized to 64×64, center-cropped, and randomly flipped horizontally. Tensors are channel-first for PyTorch training and converted to channel-last only for visualization.
What exactly is the model learning during training?The U-Net predicts the noise that was added to a clean image at a randomly chosen timestep. Training minimizes the difference between predicted and true noise (L1 loss), optimized with AdamW and a cosine learning rate schedule.
How many inference steps are used, and how are timesteps chosen?Sampling typically uses 50 DDIM steps in this chapter. The scheduler selects a subset of timesteps from the full training range (e.g., descending from near 1000 to 0), balancing speed and image quality. Fewer steps yield faster generation; more steps can refine details.
How do I create a smooth transition between two generated images?Pick two initial noise tensors (e.g., by index under a fixed seed), blend them with varying weights to form a series of intermediate noise tensors, then denoise each with the trained U-Net. The resulting images morph smoothly from one to the other, enabling controlled mixing and animation.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Text-to-Image Generator (from Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Text-to-Image Generator (from Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build a Text-to-Image Generator (from Scratch) ebook for free