Skip to content

Digitera - Simple GUI for digit prediction with neural network and MNIST

Notifications You must be signed in to change notification settings

Lucas-Meira/MNIST-Digit-Prediction

Repository files navigation

drawing

Digitera -Digit Prediction Tool With GUI

Digitera is a digit prediction tool is a Neural Network Based Digit Prediction Tool With a Graphical User Interface (GUI). It was developed in Python with Tensorflow 2.0,TKinter and with the MNIST Handwritten Digit Dataset.

Table of contents

How it works

Digitera uses Tensorflow's Keras API in tensorflow to create a Neural Network model. The actual model consists in a sequential model with convolutional layers, pooling layers and dropout layers. But you can also use your own model saved in .h5 extension!

The GUI has entirely been made in TKinter, which offers great features and is relatively easy to use.

Model Input

The model was meant to be trained with the MNIST Handwritten Digit Dataset, which offers in total 70 000 image files of 28 x 28 pixels, along with their labels. These images are divided into two groups: training images and test images, of which 10 000 are for testing and 60 000 are for training as default.

Thanks to the GUI, it is possible to generate 28 x 28 (i.e. 784 pixels in total) pixels images that can be interpreted by Digitera for prediction. To improve its functionality, some tweaks have had to be made, as the generated images were not exactly the same as those in the MNIST dataset.

Image Generation

To generate the images to be used by the NN model, Digitera gets the position of the mouser pointer and adds its values to two arrays, x and y. After that, these positions have to be normalized from the size of the drawing area into values from 0 to 28 (the pixels) for both x and y axes. With this information, a matrix of size 28 x 28 is created and, where the mouse has hovered, the element of the matrix is set to 1. The other elements are zero.

However, the model didn't have a high enough accuracy with these generated images, so two solutions have been found: improve image generation and create a own dataset to train the model.

Improving Image Generation

As mentioned before, the generated images were not exactly similar to the ones in the MNIST dataset. Therefore, in order to make them more similar to the ones in the dataset, some noise has been added to the pixels' surroundings. By trial and error, the added noise value was chosen to be a random value from 0 to 0.1. Note that the axes ticks are generated by matplotlib and don't belong to the images themselves.

This change only has deeply improved the model's prediction capability. However, there was still room for improvement, and the next change that has been made gave Digitera a very high accuracy.

Creating own dataset to train the model

In order to improve the model's prediction capabilities with Digitera's generated images, it was necessary to create an entire new dataset. That's why a new tool was made, to be able to create new images and easily label the. These images are later going to be read by the program and used by the model to train/evaluate it.

On the bottom part, the user can select the digit they are going to write and then writes it. The image is saved in its respective folder located inside the datasets folder. There's room for improvement here, but the tool was already good enough to be put to use.

With this tool, it was possible to rapidly create a dataset of 1000 images, 850 of which were used to train the NN model and 150 for its evaluation.

Results with the model trained with own dataset

Well, this maybe isn't what you expected, but the results were not excellent with this new model. This is probably due to the limited amount of images (1000), when compared to the 70 000 images on the MNIST dataset.

However, there was one change that vastly improved Digitera's prediction capabilities: Creating a "Hybrid" Model!. I call this Hybrid model because it was trained using both my own dataset and MNIST dataset. With this, the results were now much more consistent and accurate!

Available models to test

There are 4 models available for testing:

  • Model trained only with MNIST dataset
  • Model trained only with my dataset
  • Hybrid model version 1
  • Hybrid model version 2

The difference between the two hybrid models is in the number of training epochs.

License

Usage is provided under the MIT License. See LICENSE for the full details.

About

Digitera - Simple GUI for digit prediction with neural network and MNIST

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages