TensorFlow Lite image classification Android example application

Apr 19 · 4 min read


This is an example application for TensorFlow Lite on Android. It uses Image classification to continuously classify whatever it sees from the device’s back camera. Inference is performed using the TensorFlow Lite Java API. The demo app classifies frames in real-time, displaying the top most probable classifications. It allows the user to choose between a floating point or quantized model, select the thread count, and decide whether to run on CPU, GPU, or via NNAPI.

These instructions walk you through building and running the demo on an Android device. For an explanation of the source, see TensorFlow Lite Android image classification example.


We provide 4 models bundled in this App: MobileNetV1 (float), MobileNetV1 (quantized), EfficientNetLite (float) and EfficientNetLite (quantized). Particularly, we chose “mobilenet_v1_1.0_224” and “efficientnet-lite0”. MobileNets are classical models, while EfficientNets are the latest work. The chosen EfficientNet (lite0) has comparable speed with MobileNetV1, and on the ImageNet dataset, EfficientNet-lite0 out performs MobileNetV1 by ~4% in terms of top-1 accuracy.

For details of the model used, visit Image classification.

Downloading, extracting, and placing the model in the assets folder is managed automatically by download.gradle.


  • Android Studio 3.2 (installed on a Linux, Mac or Windows machine)
  • Android device in developer mode with USB debugging enabled
  • USB cable (to connect Android device to your computer)

Build and run

Step 1. Clone the TensorFlow examples source code

Clone the TensorFlow examples GitHub repository to your computer to get the demo application.

Open the TensorFlow source code in Android Studio. To do this, open Android Studio and select Open an existing project, setting the folder to examples/lite/examples/image_classification/android

Step 2. Build the Android Studio project

Select Build -> Make Project and check that the project builds successfully. You will need Android SDK configured in the settings. You'll need at least SDK version 23. The build.gradle file will prompt you to download any missing libraries.

Switch between inference solutions (Task library vs Support Library)

This Image Classification Android reference app demonstrates two implementation solutions, lib_task_api that leverages the out-of-box API from the TensorFlow Lite Task Library, and lib_support that creates the custom inference pipleline using the TensorFlow Lite Support Library. You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. See configure product flavors in Android Studio for more details.

The file download.gradle directs gradle to download the two models used in the example, placing them into assets.


`build.gradle` is configured to use TensorFlow Lite’s nightly build.

If you see a build error related to compatibility with Tensorflow Lite’s Java API (for example, `method X is undefined for type Interpreter`), there has likely been a backwards compatible change to the API. You will need to run `git pull` in the examples repo to obtain a version that is compatible with the nightly build.

Step 3. Install and run the app

Connect the Android device to the computer and be sure to approve any ADB permission prompts that appear on your phone. Select Run -> Run app. Select the deployment target in the connected devices to the device on which the app will be installed. This will install the app on the device.

To test the app, open the app called VClassify on your device. When you run the app the first time, the app will request permission to access the camera. Re-installing the app may require you to uninstall the previous installations.

Assets folder

Do not delete the assets folder content. If you explicitly deleted the files, choose Build -> Rebuild to re-download the deleted model files into the assets folder.

There you have it! Your own image classification App :)

I hope you had fun reading and/or following along. In the next story, we will look into how to build more features and interactions into this App. Stay tuned!

If you are interested in further exploring, here are some resources I found helpful along the way:

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store