Let's put everything we have learned about PyTorch and CNNs into practice! In this project, you will build and train a deep learning classifier on the famous **CIFAR-10** dataset.
The CIFAR-10 dataset contains 60,000 32x32 color images divided across 10 classes: airplanes, cars, birds, cats, deer, dogs, frogs, horses, ships, and trucks. It is a classic dataset for testing new computer vision architectures.
Before feeding images into our neural network, we must normalize pixel values and convert them into PyTorch tensors. We chain these preprocessing steps using transforms.Compose:
from torchvision import transforms
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])
Feeding all 60,000 images into a network at once is memory-prohibitive. We use a PyTorch DataLoaderto shuffle the dataset and serve images in small, manageable batches (e.g. batch size of 64).
For each batch, we perform a forward pass to calculate predictions, compute loss, zero existing gradients via optimizer.zero_grad(), perform a backward pass via loss.backward(), and update weights via optimizer.step().
To complete this project workshop, implement the following components inside the sandbox code panel: