liveBook · Manning

Chapter 7: Telling birds from airplanes: Learning from images

What you will learn in chapter 7 of Deep Learning with PyTorch, Second Edition

The introduction shifts from a simple regression example to an upcoming image-recognition task using tiny images.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction shifts from a simple regression example to an upcoming image-recognition task using tiny images.

7.1 A dataset of tiny images

Introduces CIFAR-10 as a small labeled image dataset that is useful for learning image recognition, despite being too simple for new research.

Key terms: CIFAR-10, RGB, classes

7.1.1 Downloading CIFAR-10

This section shows how to download CIFAR-10 with torchvision and identifies the common Dataset base class used by torchvision datasets.

Key terms: torchvision, datasets module, CIFAR10, training set, validation set, datasets submodule, torch.utils.data.Dataset, subclass

7.1.2 The Dataset class

This section explains how a PyTorch Dataset exposes its items and shows what an item from CIFAR-10 looks like.

Key terms: torch.utils.data.Dataset, __len__, __getitem__, sample, label, CIFAR10

7.1.3 Dataset transforms

This section shows how to use torchvision dataset transforms to turn CIFAR-10 images into tensors and explains the resulting format.

Key terms: torchvision.transforms, transform, __getitem__, datasets.CIFAR10, ToTensor, C × H × W, float32, label, permute, H × W × C

7.1.4 Normalizing data

Explains why CIFAR-10 image channels are normalized, how to compute and apply the normalization, and why normalized images may look wrong when plotted.

Key terms: zero mean, unitary standard deviation, nonzero gradients, learning rate, transforms.Normalize, transforms.Compose, ToTensor, mean, stdev, view(3, -1)

7.2 Distinguishing birds from airplanes

This section introduces a bird-watching blog’s need to automatically reject airplane photos instead of having Jane delete them manually.

Key terms: birds, airplanes, neural network

7.2.1 Building the dataset

This section builds a two-class birds-versus-airplanes dataset from CIFAR-10 and explains why the filtered object can be used as a dataset without subclassing PyTorch’s Dataset class.

Key terms: cifar10, cifar2, remap the labels, contiguous, Dataset, __len__, __getitem__

7.2.2 A fully connected model

The section builds a fully connected image classifier by flattening pixels, then explains why it needs a nonlinear hidden layer and what spatial information its structure misses.

Key terms: 1D vector, input features, nn.Linear, hidden features, activation, nonlinearity, weight matrix, spatial configuration, structurally unaware, adjacent

7.2.3 Output of a classifier

This section explains why a bird-versus-airplane classifier should produce categorical, probability-like outputs rather than a single regression value.

Key terms: categorical, regression problem, MSELoss, one-hot encoding, probabilities, softmax, binary classification, nn.Sigmoid, nn.BCELoss, nn.BCELossWithLogits

7.2.4 Representing the output as probabilities

The section turns a bird-versus-airplane classifier’s scores into probabilities, explains how labels and classification losses give those outputs meaning, and shows the corresponding PyTorch loss choices.

Key terms: softmax, probabilities, monotone, scale invariant, nn.Softmax, dimension 1, class_names, argmax, torch.max, class indices

7.2.5 Training the classifier

This section trains a bird-versus-airplane classifier with minibatches, evaluates its generalization, and shows why a fully connected model scales poorly to larger images.

Key terms: batch, minibatches, stochastic gradient descent, epoch, learning rate, DataLoader, Dataset, batch_size, shuffle, imgs

7.2.6 The limits of going fully connected

Explains why a fully connected classifier can learn from images yet struggle to generalize across changes in an object’s position.

Key terms: linear module, fully connected network, relative position, translation invariant, data augmentation, random translations, hidden features, parameters, overfitting

7.3 Conclusion

The chapter concludes by summarizing its image-classification workflow, identifying the limits of treating images as one-dimensional data, and noting where the same network design may still be useful.

Key terms: dataset, model, loss, training loop, 2D images, 1D data, translation invariance, tabular data, time-series data, bag-of-words models

7.4 Exercises

7.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 6: Using a neural network to fit the data Chapter 8: Using convolutions to generalize →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.