MR

CNN From Scratch

A convolutional neural network built from first principles in pure NumPy.

View on GitHub
Problem
Can I implement a CNN — forward and backward — with no deep-learning framework, to truly understand the maths?
Built
Hand-coded conv, pooling and dense layers with manual back-propagation, trained on MNIST.
Models / methods
A small CNN classifier on handwritten digits.
Result
Trains and classifies digits; learns meaningful first-layer edge filters.
Strength shown
First-principles understanding of how CNNs actually work.
Links
GitHubCase Study
Training loss curve
Training loss curve
Sample predictions (correct vs errors)
Sample predictions (correct vs errors)
Learned first-layer 3×3 filters
Learned first-layer 3×3 filters

Charts and diagrams are real outputs and architecture from the project.

01Objective

Build and train a CNN using only NumPy to internalise convolution, pooling and back-propagation.

02Dataset / input

The MNIST handwritten-digit dataset (28×28 greyscale images).

03Model approach

  • Conv, max-pool and dense layers implemented from scratch
  • Manual forward and backward passes (the gradients derived by hand)
  • Trained with mini-batch gradient descent

04Results / metrics

The loss curve shows stable training; sample predictions show correct classifications and the characteristic errors (e.g. 9↔7). The learned first-layer filters resemble edge/stroke detectors — evidence the network learned real features.

05Deployment / reproducibility

A single reproducible notebook.

06Limitations

  • Small model and dataset for clarity over accuracy
  • No GPU acceleration — NumPy only

07Future improvements

  • Add batch-norm and more layers
  • Vectorise the conv for speed

08Key takeaway

Shows depth of understanding — I can derive and implement the building blocks frameworks hide, not just call them.