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
