...

/

Image Classification App Using Task Library

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.

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.

Press + to interact
ImageClassifier API within the TF framework
ImageClassifier API within the TF framework

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.

Press + to interact
android {
// Various settings
// We make sure that the tflite file is not compressed for the apk file
aaptOptions {
noCompress "tflite"
}
}
dependencies {
// Various dependencies
// Import the Task Vision library dependency
implementation "org.tensorflow:tensorflow-lite-task-vision"
// Import the GPU delegate library
implementation "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.

Press + to interact
import org.tensorflow.lite.task.core.BaseOptions
import 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 ...