Stop 09 · Deep Learning FundamentalsProjects · 1/1

Train an Image Classifier

Part of the Data Science Roadmap

In short

This is where it all comes together: your own photos, a pretrained network, augmentation and honest evaluation. Finish it and you have a real deep learning project for your portfolio.

The practice project for this phase — train a CNN (from scratch or via transfer learning) to classify images into categories, and document your architecture choices and results.

The mascot sorts a pile of cat and dog photos into two cardboard boxes.

Think of it like this

Sorting a pile of pet photos

Someone hands you a shoebox of cat and dog photos to sort into two albums. At first you check carefully, then you get fast and confident. You'd still double-check the blurry ones. Your model learns the same way, and you test it on photos it has never seen.

Watch it happen

Project build plan

Collect
Split
Augment
Train
Evaluate

1/5Gather a few hundred images per class from a public dataset or your own phone. Remove duplicates.

The big ideas

What you need to know

Folder per class

data/train/cats, data/train/dogs and so on. Keras reads labels straight from folder names.

Augmentation

Random flips and rotations act like extra photos and cut overfitting on small datasets.

Show the confusion matrix

Which classes get mixed up tells you more than one accuracy number.

Ship a demo

Wrap the saved model in a small Gradio or Streamlit app so anyone can try it.

See it in code

Walk through the code

python
1import keras2from keras import layers3 4train = keras.utils.image_dataset_from_directory(5    "data/train", image_size=(160, 160), batch_size=32)6val = keras.utils.image_dataset_from_directory(7    "data/val", image_size=(160, 160), batch_size=32)8 9augment = keras.Sequential([10    layers.RandomFlip("horizontal"),11    layers.RandomRotation(0.1),12])13train = train.map(lambda x, y: (augment(x, training=True), y))

1/4Read training images and get labels from the sub-folder names.

The data pipeline is the trickiest part to get right. Plug these datasets into the transfer learning model from the earlier lesson.

Save yourself the pain

Common mistakes

Oops

Letting near-duplicate photos land in both train and test folders.

Do this instead

Remove duplicates and split by source or photo session, so the test score is honest.

Oops

Augmenting the validation and test sets too.

Do this instead

Augment only training data. Evaluate on clean, untouched images.

Your mission

First milestone: a working baseline

~45 min

Quick check

Why apply data augmentation only to the training set?

Go deeper

  1. 1Choose a manageable image dataset (not enormous) to keep training time reasonable.
  2. 2Start with transfer learning before attempting to train a CNN fully from scratch.
  3. 3Document your model's accuracy, training curves, and a few example predictions (right and wrong).

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge