liveBook · Manning

Oxford Flowers dataset

As explained in Learn Generative AI with PyTorch

A flower-image dataset used as training data for diffusion-model examples.

The Oxford Flowers dataset is a collection of about 8,000 flower images used to train a simple diffusion model. Images are standardized to 64 × 64 pixels, normalized to [−1, 1], and supplied as clean examples for synthetic noising. section 15.1.3 section 15.2

Its role is practical: clean flower images become noisy counterparts through forward diffusion, then train a denoising U-Net to predict the injected noise. Batches support repeated training iterations on a GPU. section 15.1.3 section 15.2.1

A typical preparation workflow includes:

  • Download the training split with Hugging Face’s datasets library. section 15.2
  • Apply transformations and inspect representative images with a plotted grid. section 15.2.1
  • Load tensors as three-channel images with shape (3, 64, 64), then batch them for training. section 15.2.1
  • Reduce the batch size from 4 to 2 or 1 when GPU memory is limited. section 15.2.1

Download and visualize flower images

Use load_dataset("huggan/flowers-102-categories", split="train"), apply the provided transforms, and display the first 16 images in a grid. A DataLoader can then shuffle the dataset into batches of four. section 15.2.1

Listing 15.1 Downloading and visualizing flower images
from datasets import load_dataset
from utils.ch15util import transforms
  
dataset = load_dataset("huggan/flowers-102-categories",
    split="train",)                                      #1
dataset.set_transform(transforms)
  
import matplotlib.pyplot as plt
from torchvision.utils import make_grid
  
# Plot all the images of the 1st batch in grid
grid = make_grid(dataset[:16]["input"], 8, 2)            #2
plt.figure(figsize=(8,2),dpi=300)
plt.imshow(grid.numpy().transpose((1,2,0)))
plt.axis("off")
plt.show()

A runnable listing connects dataset loading, transformation, visualization, and batching in one preparation step. section 15.2.1

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains downloading, transforming, visualizing, shaping, and batching images, but stops short of dataset labeling or curation.
Examples
Uses high-resolution color flower images, a 64 × 64 tensor format, plotted image grids, and batches of four.
What it assumes
Assumes Python and Jupyter Notebook use while introducing dataset loading, image transformations, and DataLoader batching.
What you can do after
Build a diffusion-data pipeline with Python, Hugging Face datasets, transformations, visualization, and GPU-sized batches.
How it connects
Connects datasets, forward diffusion, denoising U-Net, and Hugging Face.

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.