Fruits Prediction Android App using TensorFlow Lite| Android-Machine Learning

In this tutorial, we can create a Fruits Prediction app using TensorFlow Lite. Before going to create the app first understand what TensorFlow is.

What is TensorFlow?

TensorFlow is an end-to-end open-source platform for machine learning.

TensorFlow makes it easy for beginners and experts to create machine learning models for desktop, mobile, web, and cloud. Platforms, where you can use TensorFlow are Python, Swift, JavaScript, Android, iOS, and End to End production.

What is TensorFlow Lite?

TensorFlow Lite is a set of tools to help developers run TensorFlow models on mobile, embedded, and IoT devices. It enables on-device machine learning inference with low latency and small binary size.

Now let’s see how to create a Fruits Prediction app using TensorFlow Lite.

Get Started

1. Collect the Database

First, collect the images for your model. You can add as many images for your model. Here just, for example, I used 7 classes of fruits. Apple (60 images), Banana (60 images), Guava (60 images), Lemon (60 images), Lime (60 images), Mango (60 images), and Orange (60 images).

2. Train the model

Now you need to train our model. For that, we are using the Teachable Machine platform, provided by Google. There you can train your model by using your database.

3. Export the model

After training the model, you need to export the model in the form of TensorFlow Lite format. Here you need to export both Floating point and Quantized tflite models.

4. Add into Android

  • For this Teachable Machine, the Quantized tflite model is being used.
  • Now get the Android app example Github.
  • Now unpack the Quantized tflite model (converted_tflite_quantized.zip) and Floating-Point tflite model (converted_tflite.zip) archive exported from Teachable Machine.

  • In the quantized tflite model, you will find two files labels.txt and model.tflite. Also in the unquantized tflite model, you will find two files labels.txt and model_unquant.tflite. Both labels.txt files are the same. So you can keep only one label file. In the labels.txt file, you have all the list of classes of fruits.
  • Next, Copy the labels.txt, model_unquant.tflite and model.tflite files to the example asset folder.


  • Open


  • Modify getModelPath() and getLabelPath() to


Protected String getModelPath() {

               Return “model.tflite”;



Protected String getLabelPath() {

               Return “labels.txt”;



  • Now run the app.





 If you need the full source code please mail me at barmangolap15@gmail.com

Post a Comment