tensorflow / tensorflow/tflite-support

Select TensorFlow op(s), included in the given model, is(are) not supported by this interpreter. Make sure you apply/link the Flex delegate before inference. For the Android, it can be resolved by adding "org.tensorflow:tensorflow-lite-select-tf-ops" dependency. See instructions: https://www.tensorflow.org/lite/guide/ops_select

Open
#949 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
441
Forks
146
PR merge metrics
No merged PRs in 30d

Description

Subject:
Issue with Custom YOLOV5 TFLite Model Integration in Android App

Description:
Hi,

I'm encountering an issue while attempting to integrate a custom YOLOV5 PyTorch model in my Android application using TensorFlow Lite. I've successfully added and used other TensorFlow Lite models for object detection in my app, but when I tried to replace one of these models with my custom YOLOV5 TFLite model, I encountered the following error:

Error Message:

Select TensorFlow op(s), included in the given model, is(are) not supported by this interpreter. Make sure you apply/link the Flex delegate before inference. For Android, it can be resolved by adding "org.tensorflow:tensorflow-lite-select-tf-ops" dependency. See instructions: https://www.tensorflow.org/lite/guide/ops_select

Steps to Reproduce:

  1. Added TensorFlow Lite dependencies to my Android app:

    • TensorFlow Lite: implementation 'org.tensorflow:tensorflow-lite:2.8.0'
    • Object Detection: implementation 'org.tensorflow:tensorflow-lite-task-vision:0.3.0'
    • Certain Operations: implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.8.0'
  2. Converted a custom YOLOV5 PyTorch model to a TFLite model using the following Colab notebook: Link to Colab Notebook

  3. Replaced one of the existing TFLite models in my Android application with my custom YOLOV5 TFLite model (named 'diapers-model.tflite').

  4. Utilized the following Kotlin code for object detection within my Android app:

class ObjectDetection(private val context: Context) {

    private val IMAGE_WIDTH = 640
    private val IMAGE_HEIGHT = 640
    private val MODEL_PATH = "diapers-model.tflite"


    fun detect(bitmap: Bitmap){

        // Step 1 : Setting Object detection options
        val options = ObjectDetector.ObjectDetectorOptions.builder()
            .setMaxResults(5) // setting max output results
            .setScoreThreshold(0.5f) // set threshold value for detection
            .build()

        // Step 2 : Loading Model
        val detector = ObjectDetector.createFromFileAndOptions(
            context,
            MODEL_PATH,
            options
        )

        // Step 3 : Perform pre-image processing before running inference if needed
        val imageProcessor =  ImageProcessor.Builder()
            // Center crop the image to the largest square possible
            .add( ResizeWithCropOrPadOp(IMAGE_WIDTH , IMAGE_HEIGHT))
        // Resize using Bilinear or Nearest neighbour
        .add(ResizeOp(IMAGE_WIDTH, IMAGE_HEIGHT, ResizeOp.ResizeMethod.BILINEAR))
        .add(NormalizeOp(127.5f, 127.5f))
        // Setting model Quantization
        .add(QuantizeOp(0f, 1/255.0f))
        .build();

        // Step 4 : Creating Tensor Image
        var tensorImage = TensorImage(DataType.FLOAT32) // image input type
        tensorImage.load(bitmap)
        tensorImage = imageProcessor.process(tensorImage)

        // Step 5 : Running
        val result = detector.detect(tensorImage)

        Log.i("ModelResults", "$result")


    }


}

Model Specs:

  • Input Shape: [1, 640, 640, 3]
  • Input Image Type: Float32

Expected Behavior:
I expect my custom YOLOV5 TFLite model to perform object detection without any errors similar to the other models I've integrated.

Actual Behavior:
I encounter the error mentioned above when attempting to run inference with my custom YOLOV5 TFLite model.

Additional Information:

  • Android Studio Version: [Android Studio Giraffe | 2022.3.1 Patch 1]
  • Android API Level: [33]

Any assistance or guidance on resolving this issue would be greatly appreciated. Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides no repository file or test; start from the Kotlin ObjectDetection.detect entry point, the listed Android dependencies, and diapers-model.tflite. Reproduce the failure in the described Android setup and inspect the model/delegate integration. Done means the custom model runs inference without the unsupported-operation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin, pytorch
Domain
machine-learning, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
22/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.