This repository contains a PyTorch implementation of a Convolutional Neural Network (CNN) for classifying handwritten digits from the MNIST dataset. The model is trained using supervised learning and achieves high accuracy through convolutional feature extraction.
✅ Built with PyTorch – Uses PyTorch for defining and training the CNN.
✅ Uses MNIST Dataset – Standard dataset of handwritten digits.
✅ Convolutional Layers – Feature extraction using Conv2d
.
✅ Max Pooling – Reduces spatial dimensions and prevents overfitting.
✅ Fully Connected Layers – Maps features to digit classes (0-9).
✅ Training & Evaluation – Tracks accuracy and loss metrics.
✅ Confusion Matrix – Evaluates misclassifications.
To set up the environment, install the required dependencies using:
pip install torch torchvision numpy pandas matplotlib scikit-learn
The MNIST dataset is automatically downloaded via torchvision.datasets
. It consists of 60,000 training images and 10,000 test images, each 28×28 pixels in grayscale.
The CNN consists of:
Run the following script to train the model:
python cnnmnist.py
The model is evaluated based on:
A confusion matrix is generated to analyze misclassified digits.
📖 PyTorch Documentation
📖 Torchvision MNIST Dataset
📝 This project is licensed under the MIT License. Feel free to modify and use it!
© 2025 Syed Faizan. All Rights Reserved.