This project explores handwritten digit recognition using various machine learning and deep learning models. It includes scripts for training models on the MNIST dataset and predicting digits from custom images.
Handwritten-Digit-Recognition-using-Deep-Learning/
├── 1. K Nearest Neighbors/
│ ├── MNIST_Dataset_Loader/
│ │ ├── dataset/
│ │ │ └── ReadMe.txt <-- MNIST data goes here
│ │ └── mnist_loader.py
│ ├── knn.py # Trains and evaluates the KNN model
│ ├── Handwritten digit prediction.py # Predicts digits from an image
│ └── MNIST_KNN.pickle # (Generated) Trained model file
├── ... (other models)
├── .gitignore
└── README.md
git clone https://github.com/your-username/Handwritten-Digit-Recognition-using-Deep-Learning.git
cd Handwritten-Digit-Recognition-using-Deep-LearningIt is recommended to use a virtual environment.
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activateInstall the required Python libraries:
pip install numpy scikit-learn matplotlib opencv-python-
Download the MNIST dataset files from Yann LeCun's website. You will need the four
.gzfiles. -
Unzip the files.
-
Place the four unzipped files inside the
1. K Nearest Neighbors/MNIST_Dataset_Loader/dataset/directory. The final file names should be:train-images-idx3-ubytetrain-labels-idx1-ubytet10k-images-idx3-ubytet10k-labels-idx1-ubyte
The project contains different implementations for digit recognition.
This directory contains a classic machine learning approach using KNN.
To train the KNN classifier on the MNIST dataset, run the knn.py script. This will train the model, evaluate its accuracy, and save the trained classifier as MNIST_KNN.pickle.
cd "1. K Nearest Neighbors"
python knn.pyThe Handwritten digit prediction.py script loads the trained KNN model and uses it to predict a digit from a custom image file.
- Open
1. K Nearest Neighbors/Handwritten digit prediction.pyin an editor. - Update the
image_pathvariable (around line 123) to point to your image file. - Run the script:
python "Handwritten digit prediction.py"
The script will preprocess the image, predict the digit, and display the results.