Deep Learning (DL) · Beginner level

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

  1. Train the CNN for several epochs.
  2. Plot training and validation accuracy.
  3. Evaluate on the test set with a confusion matrix.
  4. 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

  1. Why look at misclassified images?

    Show answer

    They reveal confusing classes, label errors and unusual inputs.

  2. 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.