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:
- Installing Android Studio
- Getting The Demo Source Code
- Configuring the Project On Android Studio
- 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.
#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.
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!
Enjoyed this story? Join our Telegram group. And be part of an engaging community.
Provide your comments below
What's Your Reaction?
A Computer Science Engineer who is passionate about AI and all related technologies. He is someone who loves to stay updated with the Tech-revolutions that AI brings in. Contact: firstname.lastname@example.org