Beginner level · Module 2: Convolutional Networks for Images · Lesson 3 of 3
Training an Image Classifier
Train and evaluate a CNN on a real image data set and inspect its mistakes.
In this lesson you will
- Train a CNN with a training loop and validation
- Evaluate it and inspect misclassified images
Key concepts
training and validation loopsaccuracy and confusion matrixmisclassified examplessaving a model
The lesson
Training a CNN uses the same loop as before: batches from a DataLoader, forward pass, cross-entropy loss, backward pass and optimiser step. After each epoch, measure validation accuracy.
Evaluate on a test set at the end with accuracy and a confusion matrix. Look at misclassified images — they often reveal confusing classes, label errors or unusual photos.
Save the trained weights with torch.save(model.state_dict(), path) so you can reload the model without retraining.
Step by step
- Train the CNN for several epochs.
- Plot training and validation accuracy.
- Evaluate on the test set with a confusion matrix.
- Display ten misclassified images.
Practice activity
Complete the CNN practical activity and compare it with a fully connected network.
Expected result: A trained CNN that outperforms the fully connected network, with error analysis.
Check your understanding
-
Why look at misclassified images?
Show answer
They reveal confusing classes, label errors and unusual inputs.
-
How do you save a PyTorch model's weights?
Show answer
torch.save(model.state_dict(), path).
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.