MITB Banner

How To Setup A Simple Machine Learning Demo Application On Android 

Share

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.

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!

Share
Picture of Amal Nair

Amal Nair

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

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

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

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India

Subscribe to Our Newsletter

The Belamy, our weekly Newsletter is a rage. Just enter your email below.