Skip to content

DJ-22/MNIST-NN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MNIST Neural Network From Scratch


This project is a complete implementation of a neural network for MNSIT digit recognition, built entirely from scratch without using any deep learning frameworks.

It combines Core Neural Network Maths, V****ectorized Numerical Computing, and a User Interface that enables real-time digit drawing, prediction visualization, and dataset augmentation through user feedback.

The goal of this project is to demonstrate a strong understanding of Neural Network internals, Backpropagation, and End-to-End Machine Learning System Design, rather than relying on high-level libraries.


Project Overview

  • Fully implemented neural network using NumPy
  • Manual forward and backward propagation
  • Interactive training, testing, and inference workflow
  • Human-in-the-loop dataset expansion
  • Persistent model parameters with resume capability

Model Architecture

Input Layer

  • 784 neurons (28 × 28 pixel grayscale image)

Hidden Layer

  • 64 neurons
  • ReLU activation
  • He initialization

Output Layer

  • 10 neurons
  • Softmax activation

Loss Function

  • Categorical Cross-Entropy

Optimization

  • Batch Gradient Descent

Key Features

Neural Network from Scratch

  • No use of TensorFlow, PyTorch, Keras, or similar frameworks
  • Explicit implementation of forward propagation, backpropagation, and parameter updates
  • Fully vectorized operations for efficiency and numerical stability

Training and Evaluation

  • Configurable number of training steps and learning rate
  • Automatic checkpointing of model parameters
  • Resume training from saved parameters
  • Overall accuracy reporting
  • Per-digit accuracy analysis with visualization

Interactive Digit Recognition Interface

  • Mouse-based digit drawing on a 28 × 28 grid
  • Real-time predictions with class confidence visualization
  • Optional heatmap view of pixel intensity
  • MNIST-style preprocessing pipeline to ensure compatibility with training data

Human-in-the-Loop Learning

  • Users can mark predictions as correct or incorrect
  • Incorrect predictions allow manual label correction
  • New samples are appended directly to the dataset
  • Enables continuous dataset improvement and retraining

Digit Preprocessing Pipeline

The drawing interface applies a preprocessing pipeline designed to closely match MNIST data characteristics:

  1. Gaussian smoothing
  2. Noise thresholding
  3. Bounding box extraction
  4. Aspect-Ratio preserving resizing
  5. Centering within a 28 × 28 canvas
  6. Center-of-Mass alignment
  7. Normalization to the [0, 1] range

Project Structure

. ├── nn/ │ ├── main.py # Application entry point │ ├── menu_ui.py # Menu-Driven GUI │ ├── ui.py # Digit drawing and Interface │ ├── model.py # Neural Network implementation │ ├── train.py # Training Logic │ ├── test.py # Evaluation and Visualization │ └── data.py # Data loading and preprocessing ├── dataset/ │ ├── data.csv # Training dataset (MNIST-Style) │ └── parameters.npz # Saved Model Parameters ├── requirements.txt └── README.md

How to Run

Install dependencies:

pip install -r requirements.txt

Run the application:

python main.py

The menu allows you to:

  • Train the neural network
  • Test model performance
  • Draw digits and observe predictions

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages