Build a Tiny Image Classifier
About 24 min
Goal
By the end of this lesson, you can trace a tiny image classifier from pixels through orientation-sensitive features to a label and use a controlled image change to identify what the decision depends on.
A classifier is a sequence of transformations
Suppose a 5×5 image contains either a vertical bar or a horizontal bar.
A transparent classifier can work in two stages:
- compute a vertical-pattern score and a horizontal-pattern score;
- predict whichever orientation has the stronger score.
This is deliberately simple, but it makes the pipeline visible:
pixels -> local feature responses -> feature vector -> decision
A learned CNN makes the feature extraction trainable, but the same debugging question remains: which intermediate representation led to the final decision?
Why the intermediate feature vector matters
Imagine a vertical image produces features:
[vertical_score=8, horizontal_score=2]
The final label vertical is easy to understand.
Now imagine a preprocessing bug swaps the feature order before classification:
[2, 8]
Shapes still match. The values are still valid numbers. The semantics are reversed.
This is why “the model ran without an error” is weak evidence.
Run the complete image pipeline
The Lab creates deterministic vertical and horizontal bar images.
-
Click Run.
-
Follow the vertical-bar image in order: its pixels are a column of
1.0values in column 2; its features are[10.0, 0.0](lots of left-right change, no up-down change); its prediction is class0, vertical. The horizontal bar gives[0.0, 10.0]and class1. -
Add one bright noise pixel to the vertical image. Directly after the line
horizontal[2, :] = 1.0, add a new line:vertical[0, 0] = 1.0 -
Before running, predict: which feature score should change, and is the change large enough to flip the label?
-
Click Run. The vertical image's features become
[11.0, 1.0]. Both scores moved by 1, but the vertical-change score is still far larger, so the prediction stays0and accuracy stays1.0. One noisy pixel is small evidence compared with a whole bar. -
Press Reset afterward.
Loading lab…
Now think about rotating a vertical bar by 90 degrees while leaving the classifier unchanged. The image is still visually simple, but its orientation representation changes dramatically, so the predicted class should change.