A convolutional neural network built from scratch using only NumPy, trained and evaluated on both MNIST and Fashion-MNIST datasets. No PyTorch, no TensorFlow, just raw math.
This notebook implements every layer of a CNN by hand, including the forward pass and backpropagation:
- Conv3x3 - Convolutional layer with 3×3 filters
- MaxPool2 - 2×2 max pooling layer
- Softmax - Fully connected output layer with softmax activation
- Cross-entropy loss - Used as the training objective
- SGD - Stochastic gradient descent for weight updates
Input (28×28 grayscale)
↓
Conv3x3 (8 filters) → 26×26×8
↓
MaxPool2 → 13×13×8
↓
Softmax (FC layer) → 10 classes
Trained for 3 epochs on 1,000 samples, tested on 1,000 samples.
| Dataset | Test Loss | Test Accuracy |
|---|---|---|
| MNIST | 0.4878 | 83.5% |
| Fashion-MNIST | 0.6655 | 75.7% |
Fashion-MNIST is a harder benchmark (clothing categories vs. handwritten digits), so the lower accuracy is expected.
| Tool | Purpose |
|---|---|
NumPy |
All layer math and backprop |
TensorFlow / Keras |
Dataset loading only (mnist, fashion_mnist) |
Matplotlib |
Loss & accuracy plots |
- Manual implementation of convolution and max pooling
- Backpropagation through each layer from first principles
- Cross-entropy loss and softmax gradient derivation
- Comparing CNN performance across datasets of different difficulty