DEV Community

Cover image for Tensorflow Models on Android - Absolute Beginner
Nilesh Arnaiya
Nilesh Arnaiya

Posted on

Tensorflow Models on Android - Absolute Beginner

What is Tensorflow Lite?

  • TensorFlow Lite is an open-source framework created by Tensorflow and optimized to run inference on mobile devicesπŸ“± as well as edge devices. TFLite is used for deploying pre-trained models on android, iOS and even on your latest Raspberry Pi

This article is an introduction to TensorFlow Lite and you will learn how to train the model, convert the model, and run inference on your mobile devices.


  • Android Studio

Let's Create a Face Mask 😷 Classifier right in the browser using Google's Teachable Machine

All thanks to Prajna Bhandary for the dataset - Download

Let's Train

  1. Let's use the dataset and upload it to the Teachable Machine
    You can add as many classes with as many images you want.
    More the Images, More the training time.
    Click the Train Model and wait until it completes the training.

  2. The Advanced Tab

    • This gives you more freedom to select the basic hyperparameters that help the Neural network learn.
    • Epochs - 1 epoch is one run of each of the samples in our data and you want to keep increasing until it you get the desired predictions.
    • Batch Size - Divides your samples by the Batch Size you choose and that becomes your batch. For Eg: 112 samples/ 16 = 7 Batches
    • 7 batches to be processed by the model to finish 1 Epoch
    • Learning Rate - Size of a step that a model makes for choosing the best possible weights in a neural network. The smaller steps take a lot of time to learn which weights would be best and a high learning rate would mean we might miss some best weights possible. So tweak carefully.


  3. Export the model

    • Choose a quantized model for reducing the model size and accelerating operations on mobile devices while suffering a very minimal loss. Export
  4. Deploying on Android Devices

    • Let's create a labels.txt file with all our classes and each class on a separate line
    • We will use this MobileNet Repository for our Mask Detector and update the files respectively.
    • Download or clone the repo and open the project in Android Studio
    • Add the labels.txt file in src/main/assets/ Folder.
  • Replace the model in the assets/ folder with our trained model.

    • Change the MODEL_PATH in

    private static final String MODEL_PATH =

    • Connect the USB and RUN the app

EnjoyπŸ‘ in thee glory of creating thee Face Mask Detection Model and running it on mobile devicesπŸ“±.

Additional Resources

Top comments (4)

veselinastaneva profile image
Vesi Staneva

Great tutorial! πŸ‘ Check out the Awesome Teachable Machine List for useful resources and ideas for your next projects.

mariakhala profile image

Can you share trained model file and label

nilesharnaiya profile image
Nilesh Arnaiya

The trained model will be available from teachablemachine itself. Once you export the model, it will be downloaded.

googleaicodes profile image

This is very useful. Thanks