Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Handwritten Digit Recognition

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.

Project Structure

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

Setup

1. Clone the Repository

git clone https://github.com/your-username/Handwritten-Digit-Recognition-using-Deep-Learning.git
cd Handwritten-Digit-Recognition-using-Deep-Learning

2. Install Dependencies

It is recommended to use a virtual environment.

python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate

Install the required Python libraries:

pip install numpy scikit-learn matplotlib opencv-python

3. Download MNIST Dataset

  1. Download the MNIST dataset files from Yann LeCun's website. You will need the four .gz files.

  2. Unzip the files.

  3. 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-ubyte
    • train-labels-idx1-ubyte
    • t10k-images-idx3-ubyte
    • t10k-labels-idx1-ubyte

Usage

The project contains different implementations for digit recognition.

1. K-Nearest Neighbors (KNN)

This directory contains a classic machine learning approach using KNN.

Training the Model

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.py

Predicting from an Image

The Handwritten digit prediction.py script loads the trained KNN model and uses it to predict a digit from a custom image file.

  1. Open 1. K Nearest Neighbors/Handwritten digit prediction.py in an editor.
  2. Update the image_path variable (around line 123) to point to your image file.
  3. Run the script:
    python "Handwritten digit prediction.py"

The script will preprocess the image, predict the digit, and display the results.

About

Hand written Single digit recognition with KNN and mnist dataset

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages