A handwritten digit recognition model featuring robust optimization, very high speed and accuracy, and an architecture of my own design.
Recognizing handwritten digits accurately and efficiently requires a model that can achieve strong classification performance while maintaining low inference latency and computational cost.
This project focuses on developing an optimized deep learning model for handwritten digit recognition, with an emphasis on high accuracy, fast inference, and efficient computation.
The model is designed to provide reliable predictions while maintaining high execution speed, making it suitable for real-time and resource-efficient applications.
- Maximum execution speed
- Highly robust optimization
- Very high precision
- Advanced hyperparameter tuning with the experimental tracking method with W&B
- The modular nature of the project
- Highly professional and clean commits and branches
- Custom neural network architecture
- Includes research and scientific rationale for the entire project
- Professional README.md
MNISTVision was evaluated on the MNIST test set to measure its classification performance, inference efficiency, and computational cost.
| Metric | Score |
|---|---|
| Test Accuracy | 98% |
| Test Loss | 0.016807 |
MNISTVision is designed to provide fast inference while maintaining a lightweight computational footprint.
| Metric | Value |
|---|---|
| Training + Testing Time | 52s |
| Parameters | 3,766 |
| Model Size | 0.11 MB |
The following curves illustrate the model's learning progress throughout the training process, including changes in loss and accuracy across epochs.
The confusion matrix provides a detailed view of the model's classification performance across all ten digit classes.
The following examples demonstrate the model's predictions on unseen handwritten digit images.
MNISTVision/
β
βββ .idea/
β
βββ __pycache__/
β
βββ data/
β βββ MNIST/
β βββ raw/
β
βββ inference/
β
βββ media/
β βββ inference_media/
β
βββ research/
β βββ hyper_parametr/
β βββ batch_size.md
β βββ lr.md
β
βββ wandb/
β
βββ .gitignore
βββ LICENSE
βββ README.md
βββ SEED.py
βββ accuracy.py
βββ config.py
βββ confusion_matrix.py
βββ dataloader.py
βββ dataset.py
βββ eval.py
βββ loss.py
βββ mnist_model.pth
βββ neural_network.py
βββ optimizer.py
βββ requirements.txt
βββ tarin.py
βββ training_pipeline.py
βββ transforms.py
git clone <repository-url>
cd MNISTVisionpython -m venv .venv.venv\Scripts\activatesource .venv/bin/activatepython -m pip install --upgrade pippip install -r requirements.txtpython --version
pip --versionpython train_pipeline.pyMNISTVision uses the MNIST dataset for handwritten digit classification.
The dataset consists of grayscale images of handwritten digits from 0 to 9.
| Property | Value |
|---|---|
| Training Samples | 60,000 |
| Evaluation Samples | 10,000 |
| Number of Classes | 10 |
| Image Size | 28 Γ 28 |
| Channels | 1 (Grayscale) |
Both training and evaluation samples are converted to PyTorch tensors using ToTensor().
- Training transform:
ToTensor() - Evaluation transform:
ToTensor()
The dataset is automatically downloaded to the ./data directory when it is not already available locally.
MNISTVision uses a lightweight training configuration designed for efficient handwritten digit classification.
| Parameter | Value |
|---|---|
| Epochs | 2 |
| Batch Size | 16 |
| Learning Rate | 0.001 |
| Optimizer | Adam |
| Loss Function | Cross-Entropy Loss |
| Kernel Size | 3 |
The model is optimized using the Adam optimizer with a learning rate of 0.001.
The training objective is defined using Cross-Entropy Loss, which is suitable for the multi-class handwritten digit classification task.
The training process consists of iterating over the training dataset for the configured number of epochs, computing the classification loss, and updating the model parameters using Adam.
MNISTVision uses a fixed random seed to improve the reproducibility of training and evaluation results.
A fixed seed is configured to ensure consistent behavior across experiments involving randomized operations.
SEED = 42Using a fixed seed helps make experiments more consistent and allows results to be compared more reliably across different runs.
MNISTVision uses a custom convolutional neural network designed for handwritten digit classification.
The network consists of two convolutional blocks followed by a fully connected classification layer.
| Layer | Configuration |
|---|---|
| Conv2D | 1 β 6 channels, Kernel Size = 3, Stride = 1 |
| ReLU | Activation |
| MaxPool2D | Kernel Size = 2 |
| Conv2D | 6 β 12 channels, Kernel Size = 3, Stride = 1 |
| ReLU | Activation |
| MaxPool2D | Kernel Size = 2 |
| Flatten | Feature Flattening |
| Linear | 300 β 10 |
The final fully connected layer produces 10 output values, corresponding to the ten MNIST digit classes (0β9).
The model uses Cross-Entropy Loss for multi-class classification and the Adam optimizer for parameter optimization.
The model contains 3,766 trainable parameters.
Experiments and hyperparameter tuning were tracked using Weights & Biases (W&B).
The current implementation has several limitations:
- The model is currently evaluated only on the MNIST dataset.
- The current architecture is optimized for the relatively simple MNIST classification task and may not generalize to more complex image classification problems.
Potential improvements and extensions for MNISTVision include:
- Better and more advanced optimization
- Using other tools for experiment tracking
- Adding documents and further research
If you use MNISTVision in your research or project, please cite this repository.
@software{mnistvision,
title = {MNISTVision},
author = {Ali Asghar Ebrahimi},
year = {2026},
url = {https://github.com/aliasgharebrahimi/MNISTVision}
}@article{mnistvision_paper,
title = {},
author = {Ali Asghar Ebrahimi},
year = {2026},
journal = {},
url = {}
}This project is licensed under the Apache License 2.0.
See the LICENSE file for the full license text.
This project was developed as an independent deep learning and computer vision project.
Special thanks to the open-source community and the developers of PyTorch and TorchVision for providing the tools and frameworks used in this project.
Contributions are welcome.
If you would like to contribute to MNISTVision, please:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and keep the code clean and focused.
- Commit your changes with a clear commit message.
- Open a Pull Request describing your changes.
Please ensure that contributions are consistent with the project's goals and maintain a clean and reproducible development workflow.

