This project implements a handwritten digit classifier using a fully connected neural network built with PyTorch.
The model is trained and evaluated on the MNIST dataset, which contains grayscale images of handwritten digits (0–9).
- Task: Handwritten digit classification
- Dataset: MNIST
- Framework: PyTorch
- Model: Fully Connected Neural Network
- Output: Digit class (0–9)
Input (28 × 28 = 784)
→ Linear (128) + ReLU
→ Linear (64) + ReLU
→ Linear (10)
The MNIST dataset contains:
- 60,000 training images
- 10,000 test images
- Image size: 28 × 28 (grayscale)
The dataset is automatically downloaded using torchvision.
Install the required libraries using:
pip install torch torchvision matplotlib- Loss Function: CrossEntropyLoss
- Optimizer: Adam
- Learning Rate: 0.001
- Epochs: 5
The model achieves approximately 97% accuracy on the MNIST test dataset after training.
A sample image is displayed along with:
- Actual label
- Predicted label
After training, the model is saved as:
mnist_model.pth
- Use a Convolutional Neural Network (CNN)
- Add validation accuracy plots
- Support custom image input