liveBook · Manning

CIFAR-10

As explained in Deep Learning with PyTorch, Second Edition

A benchmark dataset of labeled natural images.

CIFAR-10 is a labeled natural-image dataset used to make computer-vision classification concrete. In PyTorch, torchvision.datasets.CIFAR10 downloads the data and returns a Dataset containing small RGB images; separate training and validation sets can be loaded by changing the train argument. section 7.1.1 section 7.5

Listing 7.1 Loading the CIFAR-10 data
# In[2]:
from torchvision import datasets
import os
data_path = '../data-unversioned/p1ch7/'
os.makedirs(data_path, exist_ok=True)
cifar10 = datasets.CIFAR10(data_path, train=True, download=True)     #1
cifar10_val = datasets.CIFAR10(data_path, train=False, download=True)    #2

Load the training and validation datasets into a local directory, allowing torchvision to download missing files. section 7.1.1

A practical CIFAR-10 preparation workflow includes:

  • Convert images to tensors with torchvision transforms. section 7.1.4 section 7.5
  • Compute per-channel statistics from the training images, then normalize each RGB channel to zero mean and unit standard deviation. section 7.1.4
  • Use Dataset and DataLoader abstractions to sample batches, change batch size, and shuffle training data. section 7.5

Using CIFAR-10 with a convolution

A CIFAR-10 image has shape 3 × 32 × 32. An nn.Conv2d(3, 16, kernel_size=3) layer applies sixteen 3 × 3 filters to its three RGB channels, producing an output shaped 16 × 30 × 30 for one image. section 8.2

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Descends from downloading images through tensor conversion, channel-statistic computation, normalization, batching, and convolutional input shapes.
Examples
Uses 32 × 32 RGB images, per-channel means and standard deviations, normalized image plots, and a 3-to-16-channel Conv2d example.
What you can do after
Apply it via torchvision and PyTorch to load, normalize, batch, and classify labeled images with neural networks.
How it connects
Connects torchvision, transforms, Dataset, DataLoader, normalization, convolution, softmax, and cross-entropy loss.

Also explained in

Compare how 2 books explain CIFAR-10 →

Related concepts

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