Robotics+AI: Deploying Keras Models using Tensorflow Lite Part 2

Shuhul Mujoo
3 min readNov 29, 2020

This is the second part of a three part series about using machine learning for robotics.

Photo by Markus Spiske on Unsplash

We left off with saving our simple model as test.tflite. (If you haven't seen the first part of this series be sure to check it out). Now we will start transferring the model into an app.

In order to make our app we will be using Android Studio. Android Studio is a IDE that allows you to make android applications. You can download android studio at https://developer.android.com/studio.

We will start by opening a empty activity. You can do this by going to the main menu and clicking start a new android studio project -> empty activity -> finish.

Then find the build.grade file for the app module under gradle scripts. We will be using gradle to import packages that we need to deploy the model.

After opening this file scroll down to dependencies and add the following code:

implementation 'org.tensorflow:tensorflow-lite:2.3.0'

Also, in the android block add the following:

aaptOptions{
noCompress "tflite"
}

It should look something like this:

If you want more advanced tensorflow lite functionality such as image processing you should add one more line of code to your dependencies

implementation 'org.tensorflow:tensorflow-lite-support:0.0.0-nightly'

Ok, now that we have a blank app with all of the tools we need to use tensorflow lite, the next step is to actually import the model.

First right click on the app folder and go to new -> folder -> assets folder

Then find the file test.tflite from the last part, and copy and paste it into the assets folder that you just created.

The model is now stored in the assets folder which means that we can access it programmatically. In the next post we will be creating a simple app and testing our model.

We are now done with the second stage in this series.

Shuhul Mujoo is a Student Ambassador in the Inspirit AI Student Ambassadors Program. Inspirit AI is a pre-collegiate enrichment program that exposes curious high school students globally to AI through live online classes. Learn more at https://www.inspiritai.com/.

--

--