Skip to content

About

An optimized handwritten digit recognition model delivering exceptional accuracy, high-speed performance, and compatibility with low-end hardware, supported by comprehensive documentation, experiment tracking, data-driven decision-making, effective troubleshooting, and a modular project structure.

Topics

Resources

Stars

92 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

211 Commits

Folders and files

Repository files navigation

MNISTVision

A handwritten digit recognition model featuring robust optimization, very high speed and accuracy, and an architecture of my own design.


Overview

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.


Key Features

  • 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

Results

MNISTVision was evaluated on the MNIST test set to measure its classification performance, inference efficiency, and computational cost.

Performance

Metric Score
Test Accuracy 98%
Test Loss 0.016807

Efficiency

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

Training Curves

The following curves illustrate the model's learning progress throughout the training process, including changes in loss and accuracy across epochs.

Training Curves

Confusion Matrix

The confusion matrix provides a detailed view of the model's classification performance across all ten digit classes.

Confusion Matrix

Sample Predictions

The following examples demonstrate the model's predictions on unseen handwritten digit images.

πŸŽ₯ Watch Sample Predictions


Project Structure

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

Installation

1. Clone the Repository

git clone <repository-url>
cd MNISTVision

2. Create a Virtual Environment

python -m venv .venv

3. Activate the Virtual Environment

Windows

.venv\Scripts\activate

Linux / macOS

source .venv/bin/activate

4. Upgrade pip

python -m pip install --upgrade pip

5. Install Dependencies

pip install -r requirements.txt

6. Verify the Installation

python --version
pip --version

7. Run the Project

python train_pipeline.py

Dataset

MNISTVision 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)

Preprocessing

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.


Training

MNISTVision uses a lightweight training configuration designed for efficient handwritten digit classification.

Training Configuration

Parameter Value
Epochs 2
Batch Size 16
Learning Rate 0.001
Optimizer Adam
Loss Function Cross-Entropy Loss
Kernel Size 3

Optimization

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.

Training Pipeline

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.


Reproducibility

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 = 42

Using a fixed seed helps make experiments more consistent and allows results to be compared more reliably across different runs.


Technical Details

MNISTVision uses a custom convolutional neural network designed for handwritten digit classification.

Model Architecture

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

Classification

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.

Parameter Count

The model contains 3,766 trainable parameters.


Experiment Tracking

Experiments and hyperparameter tuning were tracked using Weights & Biases (W&B).

View experiments on W&B


Limitations

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.

Future Work

Potential improvements and extensions for MNISTVision include:

  • Better and more advanced optimization
  • Using other tools for experiment tracking
  • Adding documents and further research

Citation

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     = {}
}

License

This project is licensed under the Apache License 2.0.

See the LICENSE file for the full license text.


Acknowledgments

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.


Contributing

Contributions are welcome.

If you would like to contribute to MNISTVision, please:

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes and keep the code clean and focused.
  4. Commit your changes with a clear commit message.
  5. 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.

About

An optimized handwritten digit recognition model delivering exceptional accuracy, high-speed performance, and compatibility with low-end hardware, supported by comprehensive documentation, experiment tracking, data-driven decision-making, effective troubleshooting, and a modular project structure.

Topics

Resources

Stars

92 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages