▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Computer Vision in Practice · Lesson 5 of 15 · 2 min read · 6 min video
Training an image classifier
Datasets, augmentation, training loops and reading the results.
📄 Download slides (PDF)· free sign-upLet's train a classifier that tells apart five kinds of vehicles on Vizag roads: car, bus, bike, auto-rickshaw and truck. The steps are the same for any image classification task.
1. Organise the data
The simplest layout is one folder per class:
Keep the classes roughly balanced, and make sure photos from the same place or the same video don't end up in both train and test. That leakage makes test scores look better than real life.
2. Augment
Data augmentation creates new training examples by changing the images a little:
- Random flips, crops and small rotations
- Changes in brightness, contrast and colour, to cover day, night and rain
- Small blurs and noise
Only augment the training set. Validation and test images stay unchanged.
3. The training loop
Every epoch: feed batches of images, measure the loss (cross-entropy), backpropagate and update the weights. Then check accuracy on the validation set.
4. Read the results
- Training accuracy rising, validation flat or falling: overfitting. Add augmentation or data, or use a smaller model
- Both low: underfitting. Train longer or use a bigger model
- Confusion matrix: shows which classes get mixed up. Autos and small cars, perhaps
5. Look at the mistakes
Open the misclassified images. You'll often find wrong labels, blurry photos or a class that needs more examples.
In one line
Train a classifier by organising clean, leak-free data, augmenting the training set, watching validation scores and studying the confusion matrix and the mistakes.
Share with a friend