liveBook · Manning

Chapter 14: Improving training with metrics and augmentation

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

The chapter introduction explains why high overall accuracy did not mean the lung-nodule classifier was useful.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduction explains why high overall accuracy did not mean the lung-nodule classifier was useful.

Key terms: non-nodule, negative samples, training and validation sets

14.1 High-level plan for improvement

This section previews the chapter’s plan to improve the nodule classifier’s evaluation and training.

14.2 Good dogs vs. bad guys: False positives and false negatives

The section uses two guard dogs to explain classification outcomes and show why overall accuracy can hide serious mistakes in nodule detection.

Key terms: false positive, true positive, false negative, true negative, percentage correct, false negatives, overall performance

14.3 Graphing the positives and negatives

This section uses a guard-dog diagram to show how ground-truth labels and a model’s thresholded predictions create four outcome groups whose counts can be used to evaluate performance.

Key terms: human label, classification threshold, true/false positives/negatives, quadrants, bark-worthiness, X-axis, vertical bark-worthiness threshold, overlapped set of events, CT voxel values, nn.Linear layers

14.3.1 Recall is Chirpy’s strength

This section defines recall and uses Chirpy’s classification threshold to show how high recall can come with many false positives.

Key terms: recall, sensitivity, true positives, false negatives, classification threshold, high recall, false positives

14.3.2 Precision is Dozer’s forte

The section defines precision, shows how a high classification threshold favors it at the cost of missed events, and explains why precision and recall are both useful during training.

Key terms: precision, true positives, false positives, classification threshold, negative events, recall, training

14.3.3 Implementing precision and recall in logMetrics

The section updates logMetrics to count classification outcomes and report precision and recall during training.

Key terms: neg_correct, trueNeg_count, true positives, false positives, false negatives, precision, recall, logMetrics, metrics_dict

14.3.4 Our ultimate performance metric: The F1 score

This section explains why the F1 score is used to evaluate the classifier and how precision, recall, F1, and sample counts are added to training logs.

Key terms: F1 score, precision, recall, harmonic mean, classification threshold, arithmetic mean, minimum, multiplication, geometric mean, logMetrics

14.3.5 How does our model perform with our new metrics?

The section interprets the model’s new metrics, explains its zero and undefined scores, and shows why they reveal a failure that earlier results obscured.

Key terms: positive samples, precision, recall, F1 score, truePos_count, falsePos_count, training results, validation results, epoch, first batch

14.4 What does an ideal dataset look like?

The section explains why the current classifier needs more separable predictions and why balancing its training data is a practical step toward that goal.

Key terms: classification threshold, label threshold, positive and negative classes, separable, class balance, negative samples, positive samples, training data, data imbalance

14.4.1 Making the data look less like the actual and more like the “ideal”

Explains why rare positive nodule samples cause training to favor negative predictions, then shows how to balance and intermix training samples in LunaDataset while leaving validation representative of real data.

Key terms: positive samples, negative samples, degenerate behavior, batch size, balanced, training, validation, discrimination, LunaDataset, ratio_int

14.4.2 Contrasting training with a balanced LunaDataset to previous runs

The section compares balanced and unbalanced training, shows why class imbalance still limits practical performance, and contrasts later validation results with training results.

Key terms: --balanced, val_neg, val_pos, class imbalance, false positives, negative validation samples, positive validation samples, epochs, validation, training set

14.4.3 Recognizing the symptoms of overfitting

This section diagnoses overfitting in the nodule classifier by comparing training and validation loss for positive samples, then explains why overall loss hides the problem.

Key terms: overfitting, training loss, validation loss, positive samples, overall loss, positive loss, negative loss, validation set, not balanced, positive training set

14.5 Revisiting the problem of overfitting

The section explains overfitting as learning training-set specifics instead of properties that generalize to unseen samples.

Key terms: general properties, training set, overfitting, generalize

14.5.1 An overfit face-to-age prediction model

A face-to-age example shows how memorizing training images differs from learning age cues, and why too little data relative to model capacity encourages overfitting.

Key terms: age signifiers, overfit model, identifying details, overfitting, training samples, model capacity, parameters

14.6 Preventing overfitting with data augmentation

The section explains how data augmentation can reduce overfitting and why useful alterations matter more than a large number of trivial variations.

Key terms: data augmentation, synthetic alterations, generalization, training set, face-to-age prediction model, red channel, flipping the image left to right, mirrored image

14.6.1 Specific data augmentation techniques

This section implements five CT-candidate augmentations and explains how to keep transformed samples representative while producing varied training examples.

Key terms: representative nature, mirroring, left-right, front-back, index-axis, getCtAugmentedCandidate, affine transformation matrix, affine_grid, grid_sample, trilinear interpolation

14.6.2 Seeing the improvement from data augmentation

This subsection compares validation results from different augmentation schemes and explains why the project continues with full augmentation despite its trade-offs.

Key terms: augmentation_dict, TensorBoard, validation data, fully augmented, positive candidate samples, recall, overfitting, rotation-augmented, precision, F1 score

14.7 Conclusion

The conclusion emphasizes trustworthy model evaluation and representative synthetic training samples as two ways to improve a classifier.

Key terms: model’s performance, evaluation, data sources, representative training samples

14.8 Exercises

14.9 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 13: Training a classification model to detect suspected tumors Chapter 15: Using segmentation to find suspected nodules →

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.