Skip to content

A Convolutional Neural Network (CNN) built with TensorFlow/Keras to classify handwritten digits from the MNIST dataset.

Notifications You must be signed in to change notification settings

Shashank-2207/CNN-Handwritten-Digit-Recognizer

Repository files navigation

CNN Handwritten Digit Recognizer ✍️

A Convolutional Neural Network (CNN) built with TensorFlow and Keras to classify handwritten digits. This project demonstrates a complete deep learning workflow, from data preprocessing and model training to evaluation and prediction on custom images.


πŸ“œ Project Overview

This project achieves a high accuracy of over 99% in classifying handwritten digits from the MNIST dataset. The key stages include:

  • Data Preprocessing: Normalizing and reshaping the image data for CNN consumption.
  • Data Augmentation: Using techniques like random rotation and zoom to create a more robust model and prevent overfitting.
  • Model Architecture: Designing a sequential CNN with multiple convolutional, batch normalization, and pooling layers.
  • Training: Implementing callbacks like EarlyStopping and ReduceLROnPlateau for efficient training.
  • Prediction Pipeline: Building a function to process and predict the digit from a user-provided image.

πŸ“Š Dataset

This project uses the classic MNIST dataset, which is conveniently included within the tensorflow.keras.datasets library. The dataset consists of 60,000 training images and 10,000 testing images of 28x28 pixel grayscale handwritten digits (0-9).

No external data download is required to run this notebook.


βš™οΈ Model Architecture

The CNN is a sequential model with the following layers:

  1. Data Augmentation: RandomRotation, RandomZoom
  2. Conv2D Block 1: 32 filters, (3,3) kernel, ReLU activation, followed by BatchNormalization and MaxPooling2D.
  3. Conv2D Block 2 & 3: Two more blocks with 64 filters each to learn more complex patterns.
  4. Flatten Layer: To convert the 2D feature maps into a 1D vector.
  5. Dense Layers: Two fully connected layers with 128 and 64 neurons. A Dropout layer (rate=0.5) is included for regularization.
  6. Output Layer: A Dense layer with 10 neurons and a softmax activation function to output a probability for each digit.

πŸš€ How to Use

  1. Clone the repository:
    git clone https://github.com/Shashank-2207/Netflix-Movie-Recommender.git
  2. Install dependencies:
    pip install -r requirements.txt
  3. Run the Notebook: Open the .ipynb file in a Jupyter or Google Colab environment. You can either run all cells to retrain the model or load the pre-trained mnist_cnn_model.keras and run the prediction cells at the end.

πŸ† Performance

The model was trained for 22 epochs (stopped early by the callback) and achieved the following performance on the validation set:

  • Final Validation Accuracy: ~99.12%
  • Final Validation Loss: ~0.03

πŸ’‘ Future Improvements

  • Hyperparameter Tuning: Use tools like KerasTuner or Optuna to find the optimal set of hyperparameters (e.g., number of filters, dense layer units, dropout rate).
  • Advanced Architectures: Experiment with more complex architectures like ResNet or Inception for potentially higher accuracy.
  • Deployment: Package the model into a web application using Flask/FastAPI or a standalone desktop app with Tkinter.

About

A Convolutional Neural Network (CNN) built with TensorFlow/Keras to classify handwritten digits from the MNIST dataset.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published