Creating Custom Model For Android Using TensorFlow

As I had promised in my previous article on building TensorFlow for Android that I will be writing an article on How to train custom model for Android using TensorFlow. So, I have written this article. Still more to come.

If you have not checked my article on building TensorFlow for Android, check here.

In this article, we will train a model to recognize the handwritten digits. Here, we will use the famous MNIST Image Dataset which like the Hello World in Machine Learning for simplicity.

Credit: The classifier example has been taken from Google TensorFlow example. The custom drawing view used in this project is taken from here.

Screenshot from sample app

Here is the complete sample project.

The complete code to train and save the model which will directly run on Android is below. Read it carefully.

Explanation of code:

  • First, it downloads the dataset from the MNIST.
  • Then it starts training the model.
  • After training, it checks accuracy.
  • Then, it saves the model to the given path and checks the accuracy again.

Check the complete python code here.

It is very easy to understand it by reading the python code.

When we run this code, we get the required trained model that will be used in the Android application.

If you are getting any problem in building the project, connect with me, I will be happy to help.

Happy Coding 🙂

Learn Machine Learning with Tensorflow from here.

Update : Check Android TensorFlow Lite Machine Learning Example

Also, Let’s become friends on Twitter, Linkedin, Github, and Facebook.

Amit Shekhar

Amit Shekhar

Co-Founder at Mindorks | Learning is a journey, let’s learn together