liveBook · Manning

Fashion MNIST

As explained in Build a Text-to-Image Generator (from Scratch)

Fashion MNIST is a dataset of 70,000 grayscale images of clothing items such as shirts, shoes, and bags.

Fashion MNIST is a dataset of 70,000 grayscale images of clothing items, including shirts, shoes, and bags. It provides a compact training task for learning diffusion models and generating new clothing images from noise. section 5.0

A typical PyTorch preprocessing pipeline performs these steps:

  • Resizes each image from one 28×28 channel to one 32×32 channel so it matches the off-the-shelf U-Net input. section 5.3.2
  • Converts pixel data from integer images into floating-point PyTorch tensors with values between 0.0 and 1.0. section 5.3.2
  • Normalizes tensor values to [−1, 1] to support faster training convergence. section 5.3.2
  • Groups shuffled examples into batches so CPUs and GPUs can update model weights more efficiently. section 5.3.2

Labeled clothing classes

The ten numerical labels map to t-shirt, trouser, pullover, dress, coat, sandal, shirt, sneaker, bag, and ankle boot. Visualizing labeled samples makes the grayscale training data easier to inspect. section 5.3.2

from torchvision import transforms

torch.manual_seed(42)  #1

tf = transforms.Compose(
    [transforms.Resize((32,32)),transforms.ToTensor(),
     transforms.Lambda(lambda x: 2*(x-0.5)),]  #2
)

Inspect the transformation pipeline that resizes, tensorizes, and normalizes Fashion MNIST images. section 5.3.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Explains dataset labels, visualization, tensor preprocessing, normalization, resizing, and batching, but not dataset internals.
Examples
Uses ten clothing classes, plotted grayscale samples, tensor transformations, and shuffled batches as concrete examples.
What it assumes
Assumes familiarity with PyTorch datasets and tensors while teaching the required image transformations and label mapping.
What you can do after
Build it from scratch by preprocessing Fashion MNIST and training a diffusion model to generate grayscale clothing images.
How it connects
Connects Fashion MNIST with diffusion models, forward diffusion, reverse diffusion, U-Net, PyTorch, and TorchVision.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.