How To Setup A Simple Machine Learning Demo Application On Android 

Tensorflow is amazing when it comes to simplicity in building and deploying machine learning applications in production. And when it comes to mobile devices Tensorflolw’s own Lite version totally saves the day. Tensorflow Lite has already marked its dominance in ML on smartphones in a generation where the entire world depends on handheld devices.

In this article, we will learn how to set up a complete working demo of a Tensorflow Lite application on an Android device. The application loads the pre-trained MobileNet model and performs inferencing to classify any object dynamically as it appears in front of the device camera.

Subscribe to our Newsletter

Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.

We will follow the 4 simple steps given below:




  1. Installing Android Studio
  2. Getting The Demo Source Code
  3. Configuring the Project On Android Studio
  4. Running The Demo

#1. Installing Android Studio

Installing Android Studio is pretty straightforward. Head to Android Studio’s official download page by clicking here

Hit the download button to automatically download the version for your operating system or go to the Download Options to select a specific version.

Once the installer is downloaded, open it and follow the standard procedure for installation.

Android Studio automatically installs all the required dependencies. Certain dependencies may require user permission, grant permission if and when prompted.

#2. Getting The Demo Source Code

We will set up one of the demos from the official Tensorflow repository. 

Clone the following GitHub repository to your local machine or download the zip file.

https://github.com/tensorflow/examples

#3. Configuring The Project On Android Studio

Open Android Studio and select the Open an existing project option. Browse to the cloned repository to the following location.

examples/lite/examples/image_classification/android

Android Studio loads and builds the project automatically. You can also build the project using Build -> Make project option.

 

The Build Output in the above image indicates a successful build without any errors.

#4. Running The Demo 

Step 1: Enable USB debugging on your android device.

To enable USB debugging in Android Pie OS, go to Settings->System->About phone, tap on the Build number seven times to unlock the Developer options.

Go back to Settings->System and you will find Developer options. Go to Developer Options and enable USB debugging.

 

 

Step 2. Connecting your device

The following image shows the Android Studio when no devices are connected.

 

Using a USB cable, connect your device to the computer. With USB debugging enabled on your device, Android Studio will detect the device and ask for user permission on the device.

Click on allow and you will see your device name on the connected devices section in Android Studio.

Step 3. Running the application

Once the device is successfully connected, we can now run the program. Running the program will install the android application on the connected device. 

To run the application click on the green play button or select  Run -> Run ‘app’. 

This may take some time. Once the process is completed you will be able to find an application called TFL Classify in your device. 

Open up the application, allow access to camera and have fun!

Amal Nair
A Computer Science Engineer turned Data Scientist who is passionate about AI and all related technologies. Contact: amal.nair@analyticsindiamag.com

Download our Mobile App

MachineHack

AI Hackathons, Coding & Learning

Host Hackathons & Recruit Great Data Talent!

AIM Research

Pioneering advanced AI market research

Request Customised Insights & Surveys for the AI Industry

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Strengthen Critical AI Skills with Trusted Corporate AI Training

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

AIM Leaders Council

World’s Biggest Community Exclusively For Senior Executives In Data Science And Analytics.

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox
MOST POPULAR