This project uses the notMNIST tutorial from the TensorFlow website. The tutorial uses a deep learning model. However the Chars 74k dataset is used for training. Moreover, a GUI is also available for predicting a single handwritten image.
This tensorflow code consists of two scripts:
- createModel.py – creates a model model/model.ckpt file based on the tutorial.
- predict.py – uses the model.ckpt (beginners tutorial) file to predict the correct integer form a handwritten letter in a .png file.
- run.py – uses the Kivy apis to start the GUI.
The following Python libraries are required.
- Tensorflow - TensorFlow
- Kivy - Kivy.
Of course TensorFlow needs to be installed. The TensorFlow website has a good manual. For windows I would suggest the anaconda version. Moreover, the model is built and tested with Python 3.4.
For using the GUI you need Kivy. The Kivy installation guide provides a comprehensive tutorial.
The easiest way is to start the GUI by running:
$ python run.py
The GUI is self explanatory. First provide an image path and click the predict button. An already trained model will provide results.
In order to use the cmd version of the predictor, the training images are included in the package. The rest is provided below.
Running is based on the steps:
- create the model file
- create an image file containing a handwritten letter
- predict the character
The easiest way is to cd to the directory where the python files are located. Then run:
python createModel.py
to create the model based on the notMNIST beginners tutorial.
You have to create a PNG file that contains a handwritten character. The background has to be white and the letter has to be black. Any paint program should be able to do this. Also the image has to be auto cropped so that there is no border around the letter.
The easiest way again is to put the image file from the previous step (step 2) in the same directory as the python scripts and cd to the directory where the python files are located.
The predict scripts require one argument: the file location of the image file containing the handwritten letter. For example when the image file is test.png’ and is in the same location as the script, run:
python predict.py test.png
The script, predict.py, uses the model.ckpt file created by the createModel.py script.