Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available: 6.13.0
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