A 2D Convolutional Neural Network (CNN) framework implemented from first principles in NumPy, without relying on PyTorch or TensorFlow for model operations or automatic differentiation.
This project was originally created upon finishing high school as an early programming project to learn Python and understand neural network mathematics. The original unedited state is tagged as v0.1.0-legacy (commit 5cdbe1f) and preserved in legacy/original_cnn.py. The repository contains both that original implementation and a modernized refactor with modular layer abstractions, type annotations, unit tests, and vectorized im2col acceleration.
Visualizing layer outputs shows how convolution filters detect edge primitives and feature boundaries:
| Layer 1 Feature Maps (16 Filters) | Layer 2 Feature Maps (32 Filters) |
|---|---|
![]() |
![]() |
Achieves 95% validation accuracy and 98% validation accuracy.
This project uses uv for dependency management.
- Install dependencies:
uv sync- Run the train script:
uv run train.py- Generate the plots:
uv run visualize.py
