Skip to content
krishivwahiPublic

About

A CNN from scratch in Java with no ML libraries, implementing: Manual 2D convolution with backprop, Max pooling with gradient routing, Softmax Cross-entropy fully connected layer, Full SGD training loop on MNIST

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Java CNN

A Convolutional Neural Network built from scratch in Java with no ML libraries, trained on the MNIST handwritten digit dataset.

Architecture

  • 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

Challenges

  • Implementing backpropagation through convolution layers
  • Debugging gradient flow across layers
  • Managing matrix dimensions manually without libraries

How it works

  • Forward pass: convolution → pooling → fully connected → softmax
  • Backward pass: full SGD with cross-entropy loss
  • No external ML libraries. Everything implemented from scratch

Setup

  1. Download MNIST CSV data from https://pjreddie.com/projects/mnist-in-csv/
  2. Place mnist_train.csv and mnist_test.csv in the data/ folder
  3. Run Main.java

Background

This project was built to solidify concepts from my NPTEL Deep Learning certification by implementing a CNN entirely from scratch in Java.

Results

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.

About

A CNN from scratch in Java with no ML libraries, implementing: Manual 2D convolution with backprop, Max pooling with gradient routing, Softmax Cross-entropy fully connected layer, Full SGD training loop on MNIST

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages