Object detection in the image is an important task for applications including self-driving, face detection, video surveillance, count objects in the image. You can implement the CNN based object detection algorithm on the mobile app.
TensorFlow Lite is a great solution for object detection with high accuracy. The SSD Model is create using TensorFlow Object Detection API to get image feature maps and a convolutional layer to find bounding boxes for recognized objects.
Android Demo App
The demo app available on GitHub. It is a simple camera app that Demonstrates an SSD-Mobilenet model trained using the TensorFlow Object Detection API to localize and track objects in the camera preview in real-time. To run the demo, a device running Android 5.0 ( API 21) or higher is required.
Building TensorFlow Lite on Android
In this tutorial we will use Bazel to build our TensorFlow Lite mobile demos APK and deploying with ADB on the command line.
- Install least SDK version(26.1.1).
- Install latest version of Bazel(0.13.0+).
- TensorFlow Lite required NDK(16b+) to build the native (C/C++)
- Bazel requires Android Build Tools 27.0.3+
- You also need to install the Android Support Repository, available through Android Studio under
Android SDK Manager -> SDK Tools -> Android Support Repository.
Clone the TensorFlow repo
$ git clone https://github.com/tensorflow/tensorflow
In the root of the TensorFlow repository, update the
tensorflow/WORKSPACE file with the api level and location of the SDK and NDK.
android_sdk_repository ( name = "androidsdk", api_level = 23, build_tools_version = "27.0.3", path = "/home/brijesh/Android/Sdk", ) android_ndk_repository( name = "androidndk", path = "/home/brijesh/Android/Sdk/ndk-bundle", api_level = 19, )
Create a Bazel WORKSPACE
Every workspace must have a text file named WORKSPACE located in the top-level workspace directory. Enter the following at the command line to create a workspace:
Download pre-trained model
Download the quantized mobilenet_ssd TensorFlow Lite model and unzip and copy
mobilenet_ssd.tflite to the assets:
Build the source code
To build the demo app, run following command in command prompt:
bazel build --cxxopt=--std=c++11 //tensorflow/contrib/lite/examples/android:tflite_demo
After building uses the following command from your workspace root to install the APK:
adb install -r bazel-bin/tensorflow/contrib/lite/examples/android/tflite_demo.apk
App uses a multi-box model to try to draw bounding boxes around the locations of people in the camera. These boxes are annotated with the confidence for each detection result.
Thanks for this article, and I have a question about the quantize ssd mobilenet model. I trained my own dataset, and I want to run this model in Android app, but I don’t know how to quantize the ssd mobilenet model. Do you know how to quantize ssd mobilent model?