Skip to content

mvparker810/digit-recognition

Repository files navigation

Digit Recognition Neural Network

A console-based neural network application for handwritten digit recognition using the MNIST dataset. Implemented from scratch with no external libraries.

Features

  • Interactive menu system for training, testing, and prediction
  • Custom neural network architecture with configurable hidden layers
  • Model serialization
  • Train on MNIST CSV dataset
  • Test accuracy on validation set
  • Predict digits from user .bmp images
  • Confidence scores with visual probability bars

Compilation

Use the provided batch file:

compile.bat

Or compile manually:

g++ -std=c++17 -O2 main.cpp neural_net.cpp mnist_loader.cpp image_loader.cpp -o digit_recognition.exe

Then run:

digit_recognition.exe

Data Setup

Training and testing data are already provided in the data folder:

data/mnist_train.csv
data/mnist_test.csv

If you'd like to replace them with your own dataset, make sure they take the same name, and that they follow the CSV format below.

CSV Format

  • First column: label (0-9)
  • Remaining 784 columns: pixel values (0-255)
  • Optional header row (auto-detected and skipped)

Where to Get MNIST Data

The MNIST dataset in CSV format can be downloaded from various sources online. Each row should contain one digit sample with 785 values total (1 label + 784 pixels). The training set typically contains 60,000 samples and the test set contains 10,000 samples.

Creating Test Images

To test with custom images:

  1. Create a BMP image, or edit the 'test_digit.bmp` already provided.
  2. Draw your digit with:
    • White foreground (the digit itself)
    • Black background
  3. The size doesn't (will be resized to 28x28)

Model Files

Trained models are saved in the models folder with .mdl extension.

Expected Performance

With recommended settings (2 hidden layers of 128 and 64 neurons, 10 epochs):

  • Training accuracy: 95-98%
  • Test accuracy: 95-97%
  • Training time: varies by hardware (progress bar shows real-time status)

Technical Details

  • Architecture: Feedforward neural network
  • Hidden activation: Sigmoid
  • Output activation: Softmax
  • Loss function: Cross Entropy
  • Optimization: Minibatch gradient descent with backpropagation
  • Weight initialization: Xavier initialization
  • Input normalization: Pixels scaled to [0, 1]
  • Data augmentation: Real-time augmentation during training to combat domain shift

Sources

About

A console-based neural network application for handwritten digit recognition using the MNIST dataset. Implemented from scratch with no external libraries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors