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.
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
EarlyStoppingandReduceLROnPlateaufor efficient training. - Prediction Pipeline: Building a function to process and predict the digit from a user-provided image.
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.
The CNN is a sequential model with the following layers:
- Data Augmentation:
RandomRotation,RandomZoom - Conv2D Block 1: 32 filters, (3,3) kernel, ReLU activation, followed by
BatchNormalizationandMaxPooling2D. - Conv2D Block 2 & 3: Two more blocks with 64 filters each to learn more complex patterns.
- Flatten Layer: To convert the 2D feature maps into a 1D vector.
- Dense Layers: Two fully connected layers with 128 and 64 neurons. A
Dropoutlayer (rate=0.5) is included for regularization. - Output Layer: A
Denselayer with 10 neurons and asoftmaxactivation function to output a probability for each digit.
- Clone the repository:
git clone https://github.com/Shashank-2207/Netflix-Movie-Recommender.git
- Install dependencies:
pip install -r requirements.txt
- Run the Notebook: Open the
.ipynbfile in a Jupyter or Google Colab environment. You can either run all cells to retrain the model or load the pre-trainedmnist_cnn_model.kerasand run the prediction cells at the end.
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
- 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.