This project builds a Convolutional Neural Network (CNN) model to classify handwritten digits using the MNIST dataset. The model learns patterns from grayscale images of digits (0–9) and predicts the correct digit.
The dataset consists of 70,000 images of handwritten digits:
- 60,000 training images
- 10,000 testing images
Each image is 28 × 28 pixels.
- Python
- Keras
- TensorFlow (Backend)
- NumPy
- Matplotlib
The dataset used is MNIST, a widely used dataset in machine learning for image classification tasks.
Features:
- 28 × 28 grayscale images
- Digits from 0 to 9
- Pre-divided into training and testing sets
Dataset Source: Keras Built-in Dataset
- Import required libraries
- Load the MNIST dataset
- Preprocess the data
- Build the CNN model
- Train the model
- Evaluate model performance
- Predict handwritten digits
The CNN model consists of the following layers:
-
Conv2D Layer
- Extracts image features
-
MaxPooling Layer
- Reduces image dimensions
-
Dropout Layer
- Prevents overfitting
-
Flatten Layer
- Converts matrix to vector
-
Dense Layer
- Fully connected neural network
-
Output Layer
- Softmax activation for digit classification (0–9)
Install required libraries:
pip install tensorflow keras numpy matplotlib- Clone the repository
git clone https://github.com/your-username/mnist-cnn-project.git- Navigate to the project folder
cd mnist-cnn-project- Run the Python script
python mnist_cnn.pyExample dataset shape:
(60000, 28, 28) (60000,)
Model accuracy after training can reach ~98% – 99%.
- Digit recognition systems
- Bank cheque processing
- Postal code recognition
- OCR systems
- AI handwriting analysis
From this project you will learn:
- Basics of Convolutional Neural Networks
- Image preprocessing
- Training deep learning models using Keras
- Evaluating model accuracy
Reshma M
This project is for educational purposes.