This project implements a deep learning model for recognizing handwritten characters (both digits and letters) using a Convolutional Neural Network (CNN). The application provides a user-friendly interface for drawing characters and getting real-time predictions.
- Handwritten digit and letter recognition (0-9, A-Z)
- Real-time prediction using a trained CNN model
- Interactive drawing canvas
- Simple and intuitive user interface
The model is trained on a combination of two datasets:
-
MNIST Database (Modified National Institute of Standards and Technology database)
- Contains 60,000 training images and 10,000 testing images
- Handwritten digits (0-9)
- 28x28 pixel grayscale images
- Download: MNIST Dataset
-
EMNIST Dataset (Extended MNIST)
- Extends MNIST to include handwritten letters (A-Z, a-z)
- Maintains the same format as MNIST (28x28 pixel grayscale images)
- Download: NIST EMNIST Dataset
-
Create a directory called
sample_datain the project root:mkdir sample_data -
Place the following dataset files in the
sample_datadirectory:mnist_train.csv- MNIST training datamnist_test.csv- MNIST test dataA_Z Handwritten Data.csv- EMNIST letters data (available from Kaggle or other sources)
-
The directory structure should look like this:
handwritten-character-recognition-deep-learning/ ├── sample_data/ │ ├── mnist_train.csv │ ├── mnist_test.csv │ └── A_Z Handwritten Data.csv ├── model/ ├── main.py ├── training.py ├── README.md └── requirements.txt
- Python 3.7+
- TensorFlow 2.x
- Keras
- NumPy
- Pandas
- Pillow
- scikit-learn
- pywin32 (for Windows GUI)
- tkinter (usually comes with Python)
-
Clone the repository:
git clone [your-repository-url]
-
Install the required packages:
pip install -r requirements.txt
-
Run the training script (optional, if you want to retrain the model):
python training.py
Note: Make sure to place the dataset files in the
sample_data/directory:mnist_train.csvmnist_test.csvA_Z Handwritten Data.csv
-
Run the application:
python main.py
-
Use the application:
- Draw a character (digit or letter) on the black canvas
- Click "Predict" to see the model's prediction
- Click "Clear" to clear the canvas and start over
The model uses a deep CNN with the following layers:
- Multiple Conv2D layers with BatchNormalization
- MaxPooling2D for downsampling
- Dropout layers for regularization
- Dense layers for classification
- Softmax activation for output (36 classes: 0-9, A-Z)
The model achieves high accuracy on both training and test sets, with data augmentation techniques applied to improve generalization.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- MNIST Database
- EMNIST Dataset
- Keras and TensorFlow teams for the deep learning framework