Instructions to use PranavDeployer221/mnist-handwritten-digit-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use PranavDeployer221/mnist-handwritten-digit-classifier with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://PranavDeployer221/mnist-handwritten-digit-classifier") - Notebooks
- Google Colab
- Kaggle
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
- ๐ง Handwritten Digit Recognition using Neural Network
- ๐ง Neural Network Architecture
- ๐ฌ Architecture Details
- Activation Functions
- Adam Optimizer
- Categorical Crossentropy
- Evaluation techniques
- Confusion Matrix
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- ๐ฌ Architecture Details
- โก Model Compilation
- Adam Optimizer
- Categorical Crossentropy
- Evaluation techniques
- Confusion Matrix
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Adam Optimizer
- ๐๏ธ Model Training
- Evaluation techniques
- Confusion Matrix
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Evaluation techniques
- ๐ Model Evaluation
- Evaluation techniques
- Confusion Matrix
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Evaluation techniques
- ๐ Error Analysis
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Application Workflow
- ๐ฎ Inference Pipeline
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Application Workflow
- ๐พ Model Serialization
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Application Workflow
- ๐ Streamlit Application
- Application Workflow
- Application Features
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Application Workflow
- ๐ Deployment
- Deployment Architecture
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Deployment Architecture
- ๐ Project Structure
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Programming
- ๐ ๏ธ Technology Stack
- Programming
- Data Processing
- Visualization
- Machine Learning
- Deep Learning
- Application
- Development Environment
- Version Control
- Deployment
- Deep Learning Fundamentals
- Data Engineering
- Model Evaluation
- Deployment
- Deep Learning Improvements
- Computer Vision Improvements
- Application Improvements
- Production Improvements
- Programming
- โ๏ธ Installation
- โถ๏ธ Run Locally
- ๐ Results
- ๐ก Key Learning Outcomes
- ๐ง Limitations
- ๐ฎ Future Improvements
- ๐ฌ Next Version: CNN
- ๐ Project Significance
- ๐จโ๐ป Author
๐ง Handwritten Digit Recognition using Neural Network
An end-to-end Deep Learning application that recognizes handwritten digits (0โ9) from 28ร28 grayscale images using a fully connected Neural Network built with TensorFlow/Keras and deployed as an interactive Streamlit application.
๐ง Handwritten Digit Recognition using Neural Network
An end-to-end Deep Learning application that recognizes handwritten digits using a Neural Network built with TensorFlow/Keras and deployed with Streamlit.
๐ Overview
Handwritten Digit Recognition is a fundamental Computer Vision and Deep Learning problem where a machine learning model learns to identify numerical digits from handwritten images.
This project implements the complete Deep Learning lifecycleโfrom raw pixel data and preprocessing to Neural Network training, evaluation, model serialization, and web deployment.
The system accepts a handwritten digit as input and predicts the corresponding digit class along with the model's confidence.
Core Pipeline
Raw Image
โ
Image Preprocessing
โ
Pixel Normalization
โ
28 ร 28 ร 1 Representation
โ
Flatten
โ
Fully Connected Neural Network
โ
Softmax Probability Distribution
โ
Predicted Digit
โ
Streamlit Application
๐ฏ Objectives
The primary objectives of this project are:
- Build a Neural Network for multi-class image classification.
- Understand the complete Deep Learning workflow.
- Process and normalize image pixel data.
- Implement a multi-layer fully connected architecture.
- Train and validate the model on handwritten digit data.
- Analyze model performance using multiple evaluation techniques.
- Perform prediction on unseen test images.
- Serialize the trained model for inference.
- Integrate the model into an interactive web application.
- Deploy the application for real-world accessibility.
๐ Dataset
The model works with handwritten digit images represented as grayscale pixel values.
Each image contains:
Image dimensions: 28 ร 28 pixels
Channels: 1 (grayscale)
Total pixels: 784
Classes: 10
Classes: 0โ9
Each image can therefore be represented as:
28 ร 28 ร 1
For the fully connected Neural Network, the image is flattened into:
28 ร 28 ร 1 = 784 features
Data Representation
Original Image
โ
28 ร 28 ร 1
โ
Flatten
โ
784-dimensional vector
๐ Exploratory Data Analysis
Before training the model, the dataset is analyzed to understand its structure and quality.
The exploration includes:
- Dataset dimensions
- Feature and target identification
- Missing-value analysis
- Pixel-value distribution
- Label/class distribution
- Image visualization
- Data type inspection
- Sample image analysis
Example visualization:
Pixel Matrix
โ
28 ร 28 values
โ
Grayscale Image
โ
Human-readable digit
โ๏ธ Data Preprocessing
1. Pixel Normalization
Raw pixel values are scaled from:
0โ255
to:
0โ1
using:
X = X / 255.0
This provides a more suitable numerical range for Neural Network optimization.
2. Reshaping
The input images are represented as:
28 ร 28 ร 1
using:
X = X.reshape(-1, 28, 28, 1)
The additional dimension represents the grayscale channel.
3. Label Encoding
The digit labels are converted into a representation suitable for multi-class classification.
For example:
7
can be represented as:
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
๐ง Neural Network Architecture
The project uses a fully connected feed-forward Neural Network.
Input Image
28 ร 28 ร 1
โ
โผ
Flatten
โ
โผ
784 Features
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Dense Layer โ
โ 128 Neurons โ
โ ReLU Activation โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Dense Layer โ
โ 64 Neurons โ
โ ReLU Activation โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Output Layer โ
โ 10 Neurons โ
โ Softmax Activation โ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Digit Prediction
0 โ 9
๐ฌ Architecture Details
| Layer | Configuration | Purpose |
|---|---|---|
| Input | 28ร28ร1 | Receives image |
| Flatten | 784 units | Converts image to vector |
| Dense | 128 neurons | Learns feature representations |
| Dense | 64 neurons | Learns higher-level representations |
| Output | 10 neurons | Predicts digit classes |
Activation Functions
ReLU
The hidden layers use the Rectified Linear Unit activation function:
ReLU(x) = max(0, x)
It introduces non-linearity and allows the network to learn complex patterns.
Softmax
The output layer uses Softmax to produce a probability distribution across the ten digit classes.
Example:
0 โ 0.01
1 โ 0.00
2 โ 0.02
3 โ 0.01
4 โ 0.00
5 โ 0.01
6 โ 0.00
7 โ 0.93
8 โ 0.01
9 โ 0.01
Final prediction:
7
โก Model Compilation
The model is compiled using:
Optimizer:
Adam
Loss Function:
Categorical Crossentropy
Metric:
Accuracy
Adam Optimizer
Adam is used to efficiently update the network weights during training.
Categorical Crossentropy
The loss function measures the difference between the true class distribution and the predicted probability distribution.
๐๏ธ Model Training
The model learns through multiple training epochs.
The training process follows:
Input Image
โ
Forward Propagation
โ
Prediction
โ
Loss Calculation
โ
Backpropagation
โ
Weight Updates
โ
Improved Model
Training performance is monitored using:
- Training loss
- Validation loss
- Training accuracy
- Validation accuracy
Training history is visualized to analyze convergence and identify potential overfitting.
๐ Model Evaluation
Model performance is evaluated using multiple metrics rather than relying only on accuracy.
Evaluation techniques
- Accuracy
- Loss
- Confusion Matrix
- Classification Report
- Individual predictions
- Error analysis
Confusion Matrix
The confusion matrix helps identify which digit classes the model confuses with one another.
For example:
Actual 7 โ Predicted 7 โ
Actual 5 โ Predicted 3 โ
Actual 9 โ Predicted 4 โ
This provides a deeper understanding of model behavior.
๐ Error Analysis
Incorrect predictions are inspected individually to understand model weaknesses.
The analysis includes:
Actual Label
โ
Model Prediction
โ
Compare
โ
Identify Incorrect Samples
โ
Visual Inspection
This helps identify difficult handwriting patterns and provides opportunities for future model improvements.
๐ฎ Inference Pipeline
Once training is complete, the trained model is used to make predictions on unseen images.
Test Image
โ
Normalize Pixel Values
โ
Reshape โ 28 ร 28 ร 1
โ
Neural Network
โ
Softmax Probabilities
โ
Argmax
โ
Predicted Digit
Example:
Input โ Handwritten "7"
Model Output:
7 โ 0.98
Prediction:
7
๐พ Model Serialization
After training, the model is saved in Keras format:
handwritten_digit_recognition.keras
The saved model contains the trained network configuration and learned parameters required for inference.
It can later be loaded without retraining:
model = tf.keras.models.load_model(
"handwritten_digit_recognition.keras"
)
๐ Streamlit Application
The trained model is integrated into a Streamlit interface to transform the machine learning model into an interactive application.
Application Workflow
User
โ
Draw / Provide Digit
โ
Image Processing
โ
Normalization
โ
28 ร 28 ร 1
โ
Saved Neural Network
โ
Prediction
โ
Digit + Confidence
Application Features
- Interactive user interface
- Handwritten digit input
- Automatic image preprocessing
- Real-time prediction
- Prediction confidence
- Lightweight deployment
๐ Deployment
The application is designed for deployment using:
GitHub
โ
Streamlit Community Cloud
โ
Live Web Application
Deployment Architecture
User
โ
โผ
Streamlit Web App
โ
โผ
Image Processing
โ
โผ
TensorFlow/Keras Model
โ
โผ
Digit Prediction
๐ Project Structure
handwritten-digit-recognition-neural-network/
โ
โโโ app.py
โ
โโโ handwritten_digit_recognition.keras
โ
โโโ requirements.txt
โ
โโโ README.md
โ
โโโ notebook/
โ
โโโ handwritten_digit_recognition.ipynb
๐ ๏ธ Technology Stack
Programming
- Python
Data Processing
- NumPy
- Pandas
Visualization
- Matplotlib
Machine Learning
- Scikit-learn
Deep Learning
- TensorFlow
- Keras
Application
- Streamlit
Development Environment
- Google Colab
- Jupyter Notebook
Version Control
- Git
- GitHub
Deployment
- Streamlit Community Cloud
โ๏ธ Installation
Clone the repository:
git clone https://github.com/YOUR_USERNAME/handwritten-digit-recognition-neural-network.git
Navigate to the project:
cd handwritten-digit-recognition-neural-network
Install dependencies:
pip install -r requirements.txt
โถ๏ธ Run Locally
Start the Streamlit application:
streamlit run app.py
The application will become available through the local Streamlit server.
๐ Results
The project evaluates the trained Neural Network using:
โ Validation Accuracy
โ Validation Loss
โ Confusion Matrix
โ Classification Report
โ Prediction Visualization
โ Error Analysis
Model performance: Add the final accuracy, loss, and other evaluation results here after completing training.
Example:
Validation Accuracy: XX.XX%
Validation Loss: X.XXXX
๐ก Key Learning Outcomes
This project provided practical experience with:
Deep Learning Fundamentals
- Neural Networks
- Dense layers
- Forward propagation
- Backpropagation
- Activation functions
- Loss functions
- Optimization
- Model training
Data Engineering
- CSV data loading
- Feature/target separation
- Image reshaping
- Pixel normalization
- Label encoding
Model Evaluation
- Accuracy
- Loss curves
- Confusion matrices
- Classification reports
- Error analysis
Deployment
- Model serialization
- Loading trained models
- Streamlit application development
- ML inference pipelines
- Cloud deployment
๐ง Limitations
Although the model performs well on MNIST-style handwritten digits, the system may perform poorly on real-world handwriting that differs significantly from the training distribution.
Potential challenges include:
- Different writing styles
- Image rotation
- Different stroke thickness
- Poor contrast
- Background noise
- Incorrect image positioning
- Non-standard image dimensions
The model is primarily designed for images similar to the training data.
๐ฎ Future Improvements
The project can be extended in several directions.
Deep Learning Improvements
- Replace the Dense Neural Network with a CNN
- Add Dropout for regularization
- Perform hyperparameter tuning
- Experiment with different optimizers
- Compare multiple architectures
Computer Vision Improvements
- Image centering
- Noise removal
- Thresholding
- Stroke normalization
- Automatic resizing
Application Improvements
- Confidence visualization
- Prediction probability chart
- Clear/reset drawing functionality
- Multiple digit recognition
- Batch image prediction
- Improved UI/UX
Production Improvements
- FastAPI inference backend
- React frontend
- Docker containerization
- REST API
- Cloud-based model serving
- Model monitoring
๐ฌ Next Version: CNN
A natural next step for this project is replacing the fully connected Neural Network with a Convolutional Neural Network (CNN).
Current architecture:
Image
โ
Flatten
โ
Dense
โ
Dense
โ
Output
Future architecture:
Image
โ
Convolution
โ
Pooling
โ
Convolution
โ
Pooling
โ
Flatten
โ
Dense
โ
Output
CNNs are generally better suited for image-related tasks because they can learn spatial and local visual features more effectively.
๐ Project Significance
This project demonstrates the transition from traditional Machine Learning to Deep Learning by implementing a complete neural-network-based image classification system.
Rather than stopping at model training, the project extends through:
Data
โ
Preprocessing
โ
Deep Learning
โ
Evaluation
โ
Inference
โ
Model Serialization
โ
Web Application
โ
Deployment
This makes the project an end-to-end AI application rather than only a notebook-based experiment.
๐ Live Demo
Try the deployed application:
๐ https://handwritten-digit-recognition-neural-network-oqnf6mdndfsmdyfzk.streamlit.app/
Draw a handwritten digit from 0โ9 and the trained Neural Network will predict the digit with a confidence score.
๐จโ๐ป Author
Pranav Sharma
Computer Science Undergraduate focused on:
- Artificial Intelligence
- Machine Learning
- Generative AI
- Deep Learning
- Software Engineering
Building practical AI-powered applications and exploring the intersection of Machine Learning and software development.
โญ Acknowledgements
This project was developed as part of my Deep Learning learning journey, with the goal of understanding Neural Networks from fundamentals through deployment.
๐ License
This project is available under the MIT Licence.
- Downloads last month
- -