A Convolutional Neural Network built from scratch in Java with no ML libraries, trained on the MNIST handwritten digit dataset.
- Input: 28×28 grayscale images
- Conv Layer: 8 filters, 5×5 kernel, stride 1, ReLU
- Max Pool Layer: 2×2 window, stride 2
- Fully Connected Layer: 1152 → 10 neurons, Softmax
- Implementing backpropagation through convolution layers
- Debugging gradient flow across layers
- Managing matrix dimensions manually without libraries
- Forward pass: convolution → pooling → fully connected → softmax
- Backward pass: full SGD with cross-entropy loss
- No external ML libraries. Everything implemented from scratch
- Download MNIST CSV data from https://pjreddie.com/projects/mnist-in-csv/
- Place
mnist_train.csvandmnist_test.csvin thedata/folder - Run
Main.java
This project was built to solidify concepts from my NPTEL Deep Learning certification by implementing a CNN entirely from scratch in Java.
Trained on full MNIST dataset (60,000 images, 3 epochs)
- Epoch 1 — Loss: 0.1336 | Accuracy: 95.93%
- Epoch 2 — Loss: 0.0649 | Accuracy: 97.99%
- Epoch 3 — Loss: 0.0508 | Accuracy: 98.40%
Test Accuracy: 98.00% (980/1000)
No overfitting observed.