- 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 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.
- 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.
- Choose a quantized model for reducing the model size and accelerating operations on mobile devices while suffering a very minimal loss.
- 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
Replace the model in the assets/ folder with our trained model.
- Change the MODEL_PATH in MainActivity.java
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📱.