An end-to-end Machine Learning project featuring a Deep Neural Network built from scratch using NumPy. This repository includes pre-trained weights, allowing you to run the interactive drawing application immediately.
- Inference-Ready: Includes
mnist_weights.pklso you can use the model without training. - Neural Network from Scratch: Logic for forward/backpropagation and gradient descent implemented without ML frameworks (no TensorFlow/PyTorch).
- Interactive GUI: A Tkinter-based whiteboard to draw digits and get real-time predictions.
- Optimized Preprocessing: Automatic image scaling and inversion to match the MNIST dataset format.
The model is a 2-layer dense neural network:
- Input Layer: 784 neurons (28x28 pixel images).
- Hidden Layer: 64 neurons with ReLU activation.
- Output Layer: 10 neurons (digits 0-9) with Softmax activation.
- Accuracy: ~95% on MNIST test data.
- Training Method: Stochastic Gradient Descent (SGD).
Ensure you have Python installed along with these dependencies:
pip install numpy pandas matplotlib pillow- Clone the Repo: Ensure the
mnist_weights.pklfile is in the same directory as your main script. - Launch: Run the Python script containing the Tkinter code.
- Interact: * Draw a digit (0-9) on the white canvas using your mouse.
- Click Predict to see the model's result.
- Click Clear to wipe the canvas for a new attempt.
To ensure the model recognizes your drawings accurately, the GUI performs these automated steps whenever you click Predict:
- Capture: Saves the current canvas drawing as a PostScript file.
- Convert: Changes the image to Grayscale (L mode).
- Invert: Flips the colors to white-on-black to match the MNIST training standard.
- Resize: Squashes the drawing down to exactly 28x28 pixels.
- Normalize: Divides pixel values by 255 to feed the network values between 0 and 1.
If you wish to retrain the model from scratch or experiment with hyperparameters:
- Data Setup: Ensure you have the
mnist_train.csvfile located in a folder nameddata/. - Execute Training: Run the
gradient_descentfunction within the training script. - Save: The script will automatically overwrite the existing
mnist_weights.pklwith your newly optimized parameters.




