This project implements a Convolutional Neural Network (CNN) using PyTorch to classify handwritten digits from the MNIST dataset. It is designed to be simple yet powerful, and supports both training and inference, including prediction on custom user-uploaded images.
- β CNN architecture built from scratch using PyTorch
- π Achieves ~98% test accuracy on MNIST
- πΌοΈ Upload and classify your own digit images (e.g.,
.png,.jpg) - π Includes visualization of preprocessing steps and predictions
- π Evaluation with loss and accuracy tracking
- β‘ GPU acceleration with CUDA support (via Google Colab)
- MNIST: A standard benchmark dataset of 28x28 grayscale images of handwritten digits (0β9).
- Automatically loaded via
torchvision.datasets.MNIST.
This project is developed and runs entirely in Google Colab, so no local setup is required.
- π Clone or download the repository.
- π§ Open
mnist_cnn_digit_classifier.ipynbin Google Colab. βΆοΈ Run each code cell in order:- Trains the CNN model from scratch
- Evaluates performance on the test set
- Accepts custom digit images for prediction
- π€ Upload a test image (28x28 or will be resized).
- Make sure it's a black digit on a white background.
- Inversion is handled automatically if needed.
- π View the predicted result with visual feedback.
MNIST-CNN-Digit-Classifier/ βββ mnist_cnn_digit_classifier.ipynb # Main Colab notebook βββ README.md
βββ images/ (Optional) Folder for custom test images βββ 1.jpg
If you want to run it locally instead of Colab, install the following(only if your device has a GPU):
pip install torch torchvision matplotlib pillowBuilt with β€οΈ using PyTorch & Google Colab by Bhargav.