Skip to content

This is a neural network built to classify digits in the MNIST dataset.

License

Notifications You must be signed in to change notification settings

UniquePython/mnist-neural-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MNIST Digit Recognizer β€” From Scratch in NumPy

This project is a handwritten digit recognizer built entirely from scratch using NumPy β€” no external machine learning libraries like TensorFlow, PyTorch, or Keras were used. It replicates a basic neural network with forward/backward propagation, softmax, ReLU, and cross-entropy loss.


✨ Features

  • Fully custom neural network with:
    • Arbitrary number of hidden layers
    • Xavier/He initialization
    • ReLU + Softmax activations
    • Cross-entropy loss + Gradient descent
  • Dropout regularization support
  • Custom data loading (from folders of .png)
  • Training on custom handwritten digits
  • Test accuracy tracking
  • Exportable and loadable models (.npz)
  • CLI prediction tool that works on any image

πŸ—‚οΈ Project Structure

MNIST_FROM_SCRATCH/
β”œβ”€β”€ code/ # All Python source code
β”‚ β”œβ”€β”€ network.py # Core neural network logic
β”‚ β”œβ”€β”€ predict.py # CLI tool for predictions
β”‚ β”œβ”€β”€ data_loader.py # Loads MNIST/custom data
β”‚ β”œβ”€β”€ nn_math.py # Activation functions & loss
β”‚ β”œβ”€β”€ main.py # Training script
β”‚ β”œβ”€β”€ preprocessing.py # Preprocesses custom data to match MNIST preprocessing
β”œβ”€β”€ custom_data/ # Your own 28Γ—28 black-bg white-digit PNGs
β”œβ”€β”€ data/ # Raw MNIST files (idx format)
β”œβ”€β”€ models/ # Trained .npz model files
β”œβ”€β”€ test_data/ # Digits to test the model
└── README.md

Predicting images

To classify images:

python predict.py <model_path> <image(s)_or_folder>

I suggest using the augmented_more_epochs.npz model from the models/ folder as it is the best one.

About

This is a neural network built to classify digits in the MNIST dataset.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages