tensorflow / flutter-tflite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue while using GpuDelegateV2 in an isolate on android.

Arna-Maity opened this issue · comments

I am getting the following error while trying to run the image_classification_mobilenet example application from this repo using the GpuDelegateV2 :

E/tflite  ( 7414): TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread where it was initialized.
E/tflite  ( 7414): Node number 31 (TfLiteGpuDelegateV2) failed to invoke.
E/flutter ( 7414): [ERROR:flutter/runtime/dart_isolate.cc(1097)] Unhandled exception:
E/flutter ( 7414): Bad state: failed precondition
E/flutter ( 7414): #0      checkState (package:quiver/check.dart:74:5)
E/flutter ( 7414): #1      Interpreter.invoke (package:tflite_flutter/src/interpreter.dart:164:5)
E/flutter ( 7414): #2      Interpreter.runInference (package:tflite_flutter/src/interpreter.dart:214:5)
E/flutter ( 7414): #3      Interpreter.runForMultipleInputs (package:tflite_flutter/src/interpreter.dart:180:5)
E/flutter ( 7414): #4      Interpreter.run (package:tflite_flutter/src/interpreter.dart:172:5)
E/flutter ( 7414): #5      IsolateInference.entryPoint (package:image_classification_mobilenet/helper/isolate_inference.dart:84:19)
E/flutter ( 7414): <asynchronous suspension>

I am running this on Android 13 (API Level 33). The application starts up fine but it doesn't perform any inference:

Screenshot_20231202-074039_image_classification_mobilenet

Meanwhile when I use the XNNPackDelegate instead of GpuDelegateV2, it works fine:

Screenshot_20231202-074301_image_classification_mobilenet

@Arna-Maity Could you post how you created the interpreter?
I think you need to instantiate the interpreter in the isolate as the message indicates.

TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread where it was initialized.

Edit: Sorry, did not read that you were running the example. The example needs to be updated so that the interpreter is initialized in an isolate.