This project demonstrates how to train a neural network to classify handwritten digits from the MNIST dataset using PyTorch.
The MNIST dataset contains:
-
60,000 training images
- split into 50,000 for training, 10,000 for validation
-
10,000 test images Each image is 28×28 grayscale and represents digits 0–9.
├── MNIST.ipynb
├── models/
├── images/
└── README.md
git clone https://github.com/8Whoknow3/MNIST.git
cd mnist-classifierMake sure you have Python 3.7+ and install the required libraries:
pip install torch torchvision matplotlib scikit-learn tqdmjupyter notebook MNIST.ipynb| Metric | 🧮 Linear Model | 🧠 CNN Model |
|---|---|---|
| Final Val Acc | 0.9678 | 0.9846 |
| Final Val F1 | 0.9676 | 0.9846 |
| Test Accuracy | 0.9691 | 0.9891 |
| Test F1 Score | 0.9690 | 0.9891 |
✅ Model checkpoints saved in the
models/directory. 🖼️ Confusion matrix saved in theimages/folder.
The notebook includes the following architectures:
- 🔹 Linear Model using
nn.Linear - 🔹 Convolutional Neural Network (CNN) using
nn.Conv2d
- MNIST digit classification using PyTorch
- Custom training and validation loops
- Live progress bar via
tqdm - Evaluation with F1 Score and Accuracy
- Confusion matrix visualization
- GPU acceleration support
Linear Model CNN Model