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.
- 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
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
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.