Object Detection in Android using EfficientDet lite Models with Images | Java & Kotlin | Tensorflow Lite
In this article, we will learn to use EfficientDet Models in Android for performing object detection with images. So in the application
1: The user can choose images from the gallery
2: Or capture images using the camera
3: Then that image will be passed to our Efficientdet model
4: And based upon results returned by the model rectangles will be drawn around detected objects
and the models you can use are
1: EfficientDet lite0
2: EfficientDet lite1
3: EfficientDet lite2
4: EfficientDet lite3
So let’s begin.
Note: If you want to train your custom object detection models and build Android Apps then join our new course on 92% discount
Train Object Detection Models for Android — The 2024 Guide
In that course, you will learn to
1: Train custom object detection model in Tensorflow Lite fromat
2: Use that model in Android with images and live camera footage
3: Use SSD MobileNet, EfficientDet and YOLO models in Android
Join now and avail huge discount
Getting Starter Application Code
The first step is to get the application code from Github. So if you are using java language then take the code from here and if you are using kotlin take the code from here
Getting EfficientDet Models
If you have efficientdet models then you can skip this step otherwise you can go to this link and download all efficientdet models from this link
You will find all 4 efficientdet models in tflite format
Running Starter Application Code
After getting the starter application code
1: open project code inside the android studio
2: Run the starter application
In that application, we are using our custom efficiendet model with images and that model can recognize four different fruits apple, watermelon, kiwi and pineapple.
So when you will click on the center image gallery will be opened and the user can choose an image from the gallery when you will long click on the center image camera will be opened and you can capture an image from the camera. After choosing or capturing the image that image will be passed to our object detection model and rectangles will be drawn around detected objects.
Using EfficientDet Models in that starter application
Firstly you need to copy the model file and paste it into the assets folder of the android studio project. So if you want to use EfficientDet lite0 then copy that file and paste it inside the assets folder.
Then open the MainActivity.java file and here we just need to change the model file name to use efficientdet lite0 model. So change this model.tflite to efficientdet_lite0.tflite so that our efficientdet_lite0 model will be used instead of this model.tflite file.
After changing this name you can simply run the application and test it, and this application efficientdet lite0 model will be used.
Using Other EfficientDet Models
If you want to use other efficientDet models like efficientdet lite 1, lite 2, or lite3 then you just need to add that model to the assets folder and change the name in MainActivity and that’s it
Code Explanation
In this application, we are performing object detection using a module named lib_task_api and that module is added to the project
All our object detection-related code is present in that module and we are using the TFLiteObjectDetectionAPIModel class of this module to perform object detection in our app. Firstly we are creating the object of this class and pass our model file name to it. And when this object is created our model will be loaded. Don't change other parameter values like label file name, input image size, and quantization because these are not being used and will be taken from our model file itself. So we don’t need to specify them.
Then we are using recognizeImage method of this class and passing the image that the user selected from the gallery or captured using the camera. And inside this method, our image will be passed to the model and we will get the results returned by the model.
Then based on the results we will draw the rectangles around the detected objects
Train Object Detection Models for Android — The 2024 Guide
If you want to train your custom object detection models for Android and IOS then join our new course on udemy. In that course you will learn to
1: Train custom object detection model for Android and IOS
2: Use that model in Android with image and live camera footage
3: Use SSD MobileNet, EfficientDet, and YOLO models in Android with both images and live camera footage
Mobile Machine Learning
Learn the use of machine learning and computer vision in Android, Flutter & React Native with our Mobile Machine Learning courses. You can avail discount on the following Mobile Machine learning courses
Android Machine Learning Courses
Face Recognition in Android — Build Attendance Systems
Train Object Detection Models & build Android Applications
ChatGPT & Android — Build Chatbots & Smart Apps for Android
Android Machine Learning with TensorFlow lite in Java/Kotlin
Android & Regression: Train Prediction ML models for Android
Flutter Machine Learning Courses
Machine Learning for Flutter The Complete 2023 Guide
Face Recognition and Detection in Flutter — The 2024 Guide
Flutter and Linear Regression: Build Prediction Apps Flutter
ChatGPT & Flutter: Build Chatbots & Assistants in Flutter
Train Object Detection and classification models for Flutter
React Native Courses
ChatGPT & React Native — Build Chatbots for Android & IOS
Connect With Me
My Courses: https://www.udemy.com/user/e1c14fb5-1c9b-45ef-a479-bbc543e33254/
My Facebook: https://www.facebook.com/MobileMachineLearning
Youtube Channel: https://www.youtube.com/channel/UCuM6FHbMdYXQCR8syEtnM9Q