Seperate Labels.txt file for TensorFlow Lite Object Detection Android App

I was wondering whether anyone had any idea of how to use a tflite model that has a seperate Labels.txt file rather than inbuilt metadata from the model?

I’m having a look at the TensorFlow Lite Object Detection Android Demo app with realtime video feed listed here:

Object Detection App

I see this a lot with classification apps such as the Pose Estimation Android Demo and the Flower Classification Android Demo, just wondering whether this is a big step for Object Detection apps and whether anyone has any examples of it implemented? Better yet, any hints on how to do this in the Object Detection app?

Pose Estimation App for reference.

@wwfisher Welcome to Tensorflow Forum!

Here’s how to integrate a separate Labels.txt file into the TensorFlow Lite Object Detection Android Demo app, please try bleow and let us know if any of the below works for you:

  • Add the Labels.txt file to the assets directory of your Android project. Read the file using AssetManager.

  • The model’s output is typically a list of indices corresponding to detected objects. Use the loaded labels to map these indices to their corresponding label names:

  • In the ObjectDetector.java class:

    • Access the loaded labels (you might need to pass them as a parameter).
    • Replace the labelList array (which holds hardcoded labels) with the loaded labels.
    • Update logic that draws bounding boxes and labels to use the loaded labels.

Let us know if this helps!