faizan
docs: add README.md for Hugging Face Spaces deployment
ecc050c

A newer version of the Gradio SDK is available: 6.13.0

Upgrade
metadata
title: MNIST Digit Classifier
emoji: πŸ”’
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 3.50.0
app_file: app.py
pinned: false

πŸ”’ MNIST Handwritten Digit Classifier

A Convolutional Neural Network (CNN) trained to recognize handwritten digits (0-9) with 99.17% accuracy on the MNIST test set.

🎯 Model Details

  • Architecture: 2-layer CNN with batch normalization and dropout
  • Parameters: 421,066
  • Training Data: 60,000 MNIST handwritten digits
  • Validation Data: 9,000 images (stratified split)
  • Test Accuracy: 99.17%
  • Framework: PyTorch 2.0.1

Architecture Breakdown

Input (28x28x1)
β†’ Conv2D(32, 3x3) + BatchNorm + ReLU
β†’ Conv2D(64, 3x3) + BatchNorm + ReLU + MaxPool(2x2)
β†’ Dropout(0.25)
β†’ Fully Connected(128) + ReLU + Dropout(0.5)
β†’ Output(10) + Softmax

πŸš€ Usage

Draw a digit in the canvas or upload an image. The model will predict the digit and show confidence scores for all 10 classes.

Tips for Best Results

  • Draw the digit large and centered
  • Use clear, bold strokes
  • Keep digits similar to MNIST style (white on black background)
  • Numbers should be recognizable and not ambiguous

πŸ“Š Performance Metrics

Metric Value
Test Accuracy 99.17%
Training Time 20 epochs (~10 mins on GPU)
Inference Time <50ms per image

Per-Class Performance

All digits achieve >98% accuracy, with digit '1' being the easiest (99.7%) and digit '5' being the most challenging (98.3%).

πŸ› οΈ Technical Stack

  • Deep Learning: PyTorch 2.0.1
  • Interface: Gradio 3.50.0
  • Experiment Tracking: MLflow
  • Deployment: Docker + Hugging Face Spaces

πŸ“ Project Structure

β”œβ”€β”€ app.py                 # Gradio interface
β”œβ”€β”€ models/
β”‚   └── best_model.pt      # Trained CNN weights
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ models.py          # CNN architecture
β”‚   β”œβ”€β”€ inference.py       # Inference wrapper
β”‚   └── data_loader.py     # MNIST data utilities
β”œβ”€β”€ examples/              # Sample digits (0-9)
└── requirements.txt       # Python dependencies

πŸ”¬ Training Details

  • Optimizer: Adam (lr=0.001)
  • Loss Function: Cross-Entropy
  • Data Augmentation: Rotation (Β±10Β°), scaling (0.9-1.1x)
  • Regularization: Dropout (0.25, 0.5) + Batch Normalization
  • Early Stopping: Patience=5 epochs on validation loss

πŸ“ˆ Training Results

  • Converged in 20 epochs
  • No overfitting observed (train/val gap <0.5%)
  • Stable learning curve with LR scheduling

πŸŽ“ About MNIST

The MNIST dataset is a classic benchmark in computer vision, containing 70,000 grayscale images of handwritten digits (28Γ—28 pixels). It's widely used for training and testing image classification models.

πŸ“ License

MIT License - This project is for educational purposes.

πŸ™ Acknowledgments

  • MNIST dataset by Yann LeCun et al.
  • Built as part of an AI Engineering course focusing on MLOps best practices