Image Classification App Using Task Library
Use the ImageClassifier API of the TF Lite Task Library to deploy a DL model to an Android app for image classification.
We'll cover the following...
The ImageClassifier
API of the Task Library
The ImageClassifier
API of the TF Lite Task Library simplifies the process of loading a pretrained image classification model and performing classification on mobile devices. The ImageClassifier
API abstracts away the complexities of model loading, input preprocessing, and result interpretation, allowing us to easily integrate image classification functionality into our mobile apps.
Image classification using the ImageClassifier
API
To use the ImageClassifier
API of the Task Library for image classification, we import its dependencies into the module’s build.gradle
file. We specify that the build system doesn’t compress the model file. We also have to copy the .tflite
model file to the assets directory.
Note: Gradle is an open-source build tool used to build numerous types of software.
android {// Various settings// We make sure that the tflite file is not compressed for the apk fileaaptOptions {noCompress "tflite"}}dependencies {// Various dependencies// Import the Task Vision library dependencyimplementation "org.tensorflow:tensorflow-lite-task-vision"// Import the GPU delegate libraryimplementation "org.tensorflow:tensorflow-lite-gpu-delegate-plugin"}
Next, we import the ImageClassifier
API from the Task Library to our app’s activity class that handles image classification.
import org.tensorflow.lite.task.core.BaseOptionsimport org.tensorflow.lite.task.vision.classifier.ImageClassifier
The Task Library follows the builder pattern to create complex objects with various options. This pattern of object construction allows step-by-step ...