Deep Learning · Keras · TensorFlow · CV

CIFAR-10
Image
Classifier.

A custom convolutional neural network built in Keras that classifies 32×32 images across 10 object categories — achieving 73.2% test accuracy trained from scratch on 50,000 images.

CIFAR-10 — 10 object classes
✈️airplane
🚗automobile
🐦bird
🐱cat
🦌deer
🐶dog
🐸frog
🐴horse
🚢ship
🚛truck
Test accuracy 73.2%
73.2%
Test accuracy
// 10-class classification
50,000
Training images
// 32×32 RGB
10,000
Test images
// held-out set
10
Object classes
// balanced dataset

CNN design.

Input → 32 × 32 × 3 (RGB image, normalised 0–1) ── Block 1 ────────────────────────────────────── Conv2D 32 filters 3×3 ReLU padding=same Conv2D 32 filters 3×3 ReLU padding=same MaxPool2D 2×2 stride 2 → 16 × 16 × 32 Dropout 0.25 ── Block 2 ────────────────────────────────────── Conv2D 64 filters 3×3 ReLU padding=same Conv2D 64 filters 3×3 ReLU padding=same MaxPool2D 2×2 stride 2 → 8 × 8 × 64 Dropout 0.25 ── Block 3 ────────────────────────────────────── Conv2D 128 filters 3×3 ReLU padding=same Conv2D 128 filters 3×3 ReLU padding=same MaxPool2D 2×2 stride 2 → 4 × 4 × 128 Dropout 0.25 ── Classifier ─────────────────────────────────── Flatten → 2,048 units Dense 512 ReLU Dropout 0.50 Dense 10 Softmax → class probabilities ────────────────────────────────────────────────── Optimizer: Adam lr = 0.001 Loss: Categorical Crossentropy Augment: horizontal flip · random crop · colour jitter Test acc: 73.2%

What each block does.

Conv2D ×6 Feature extraction — small 3×3 kernels slide over the image detecting edges, textures, and increasingly complex patterns across three blocks of increasing depth (32 → 64 → 128 filters) 32 / 64 / 128 filters
MaxPool ×3 Spatial downsampling — 2×2 max pooling halves the spatial dimensions after each block, reducing computation and building translation invariance 2×2 stride 2
Dropout ×4 Regularization — randomly zeroes 25% of activations after each conv block and 50% before the final output, preventing co-adaptation and reducing overfitting on the small 32×32 images 0.25 / 0.50
Flatten Bridge to classifier — reshapes the 4×4×128 feature map into a 2,048-element vector for the fully connected layers → 2,048 units
Dense ×2 Classification head — a 512-unit hidden layer with ReLU learns high-level combinations of features; the final 10-unit Softmax layer outputs a probability for each class 512 → 10

How the model was trained.

Data augmentation

  • Horizontal flip — randomly mirrors images left-right, doubling effective training data
  • Random crop — pads and re-crops to 32×32, teaching position invariance
  • Colour jitter — varies brightness and saturation to handle lighting differences
  • Normalisation — pixel values scaled to [0, 1] for stable gradient flow

Optimizer & schedule

  • Adam — adaptive learning rate optimizer, well suited to CNNs
  • lr = 0.001 — standard starting point for image classification
  • Categorical crossentropy — correct loss function for 10-class softmax output
  • Batch size 64 — good balance between gradient noise and memory

Performance context.

🎯
Accuracy

73.2% — built from scratch

73.2% on CIFAR-10 is a strong result for a custom CNN trained from scratch — no pretrained weights, no transfer learning. The baseline (random guessing) is 10%. State-of-the-art approaches using large pretrained models reach ~99%, but those use orders of magnitude more compute and data.

73.2% test acc10% baseline
🔬
Hardest classes

Cat vs. dog confusion

CIFAR-10's hardest classes are cat/dog and automobile/truck — visually similar at 32×32 resolution. The model performs strongest on structurally distinct classes like airplane and ship, and weakest on fine-grained animal distinctions — a known pattern in CNN benchmarks.

Cat/dog hardShip/plane easy
📈
Design decisions

What made the difference

Three blocks of increasing filter depth (32→64→128) with dropout after each was the key structural choice. Without dropout the model overfit significantly — val accuracy stayed ~10% below train. Data augmentation added ~3-4% improvement on top.

Dropout criticalDepth scaling
~ python train.py --epochs 50 --batch-size 64
Epoch 1/50 — loss: 1.8842 — acc: 0.3241 — val_acc: 0.3890
Epoch 10/50 — loss: 1.1204 — acc: 0.6018 — val_acc: 0.5934
Epoch 25/50 — loss: 0.8341 — acc: 0.7102 — val_acc: 0.6891
Epoch 40/50 — loss: 0.7203 — acc: 0.7480 — val_acc: 0.7218
Epoch 50/50 — loss: 0.6914 — acc: 0.7601 — val_acc: 0.7320
 
~ python evaluate.py --checkpoint best.h5
Test set accuracy: 73.2%
Per-class accuracy:
airplane 80.1% · automobile 81.3% · bird 68.4%
cat 59.2% · deer 72.8% · dog 62.1%
frog 79.4% · horse 78.9% · ship 83.0% · truck 77.6%
~

Built with.

CategoryToolPurpose
FrameworkKeras + TensorFlow backendModel definition, training loop, layer API
DatasetCIFAR-10 60,000 images50k train / 10k test, 10 classes, 32×32 RGB
OptimizerAdam lr=0.001Adaptive gradient descent for CNN training
LossCategorical CrossentropyStandard multi-class classification loss
AugmentationKeras ImageDataGeneratorHorizontal flip, random crop, colour jitter
RegularizationDropout 0.25 / 0.50Prevents overfitting in conv blocks and classifier
EvaluationPer-class accuracyIdentifies which classes the model struggles with