liveBook · Manning

Chapter 8: Image classification

What you will learn in chapter 8 of Deep Learning with Python, Third Edition

The chapter introduction places ConvNets in the history of deep learning’s success in computer vision and describes the widespread use of vision models today.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction places ConvNets in the history of deep learning’s success in computer vision and describes the widespread use of vision models today.

Key terms: convolutional neural networks, ConvNets, CNNs, computer vision, image classification

8.1 Introduction to ConvNets

Introduces a small ConvNet for MNIST by tracing its image input through feature maps to a classifier and comparing its test accuracy with a densely connected model.

Key terms: ConvNet, Conv2D, MaxPooling2D, image_channels, channels_first, feature map, channels, GlobalAveragePooling2D, Dense, softmax

8.1.1 The convolution operation

This section explains how convolutions learn reusable local image patterns, produce feature maps, and use padding and strides to control output size.

Key terms: dense layers, convolution layers, local patterns, translation invariant, spatial hierarchies, feature map, spatial axes, depth axis, channels, filters

8.1.2 The max-pooling operation

This section explains how max pooling downsamples ConvNet feature maps, why downsampling supports spatial feature hierarchies, and why max pooling is often preferred to other downsampling methods.

Key terms: max pooling, feature maps, MaxPooling2D, stride, downsampling, spatial hierarchy of features, channels, average pooling, strided convolutions, feature presence

8.2 Training a ConvNet from scratch on a small dataset

This section introduces the practical problem of classifying images with limited data, using a cats-versus-dogs dataset as its example.

Key terms: image-classification model, small datasets, training, validation, testing

8.2.1 The relevance of deep learning for small-data problems

This section explains why small image datasets can sometimes support useful ConvNets and how pretrained models offer another way to work with little data.

Key terms: enough samples, ConvNet, local, translation-invariant features, well regularized, custom feature engineering, pretrained classification models, bootstrap, feature reuse

8.2.2 Downloading the data

This section shows how to obtain the Dogs vs. Cats images and create a small, balanced training, validation, and test dataset.

Key terms: Dogs vs. Cats dataset, Kaggle API key, kagglehub, train.zip, test1.zip, training set, validation set, test set, subsampled dataset, balanced binary classification problem

8.2.3 Building your model

This section builds a larger ConvNet for dogs-versus-cats classification and explains its feature-map dimensions, input scaling, and binary-classification setup.

Key terms: Conv2D, MaxPooling2D, feature maps, capacity, GlobalAveragePooling2D, binary classification, Dense, sigmoid, binary crossentropy, adam optimizer

8.2.4 Data preprocessing

This section turns image files into batched datasets for a ConvNet, trains and checkpoints the model, and interprets its validation and test results as evidence of overfitting.

Key terms: image_dataset_from_directory, tf.data.Dataset, RGB, batches, batch(), shuffle(), prefetch(), map(), fit(), validation_data

8.2.5 Using data augmentation

This section uses random image transformations and dropout to reduce overfitting when training a ConvNet on a small dataset.

Key terms: data augmentation, random transformations, generalize, data augmentation layers, Dataset, map(), RandomFlip, RandomRotation, RandomZoom, intercorrelated

8.3 Using a pretrained model

This section explains why a pretrained image model can help with a small image dataset and introduces ImageNet-trained Xception as an example.

Key terms: pretrained model, spatial hierarchy of features, small-data problems, ImageNet, ConvNet, dogs-versus-cats classification

8.3.1 Feature extraction with a pretrained model

This section shows how to reuse a pretrained ConvNet’s features for a new image classifier, comparing a fast feature-recording approach with a slower approach that supports data augmentation.

Key terms: feature extraction, convolutional base, backbone, feature maps, densely connected classifier, convolution layers, KerasHub, ImageConverter, from_preset(), pretrained checkpoint

8.3.2 Fine-tuning a pretrained model

This section explains how to fine-tune a pretrained image classifier safely, including which layers to train and why to use a low learning rate.

Key terms: fine-tuning, feature extraction, model base, fully connected classifier, freeze, unfreeze, convolutional base, error signal, BatchNormalization, partial fine-tuning

8.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 7: A deep dive on Keras Chapter 9: ConvNet architecture patterns →

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.