This project demonstrates handwritten digit classification using the MNIST dataset with a Convolutional Neural Network (CNN) built in PyTorch.
The goal is to train a deep learning model to recognize digits (0β9) from 28Γ28 grayscale images. The notebook covers data preparation, model architecture, training loop, and evaluation.
The MNIST dataset consists of:
- 60,000 training images
- 10,000 test images
- Each image is 28x28 pixels, grayscale, and represents a digit from 0 to 9.
The CNN architecture includes:
- Two convolutional layers with ReLU activations and max pooling
- A fully connected layer
- Dropout regularization to prevent overfitting
- Output layer with 10 neurons (one for each digit class)
- Final Validation Accuracy: ~98.5%
- Loss: Reduced significantly with good generalization
- F1 Score: High precision and recall balance
Example performance metrics (varies per run):
| Metric | Value |
|---|---|
| Final Train Loss | ~0.17 |
| Final Val Loss | ~0.03 |
| Validation Accuracy | ~98.5% |
| Validation F1 Score | ~0.985 |
| Test Accuracy | ~99.3% |
| Test F1 Score | ~0.993 |
- Clone the repository:
git clone https://github.com/your-username/mnist-cnn-classifier.git
cd mnist-cnn-classifier- Install dependencies (preferably in a virtual environment):
pip install torch torchvision matplotlib- Run the notebook:
Open
Mnist.ipynbin Jupyter or VS Code and run the cells step-by-step.
After training, the notebook includes visualizations of sample predictions showing the model's high accuracy on test images.
- Implement training with a learning rate scheduler
- Add confusion matrix and per-class accuracy
- Experiment with data augmentation
- Test on corrupted MNIST variants