I upgraded tensorflow-lite and tensorflow-lite-gpu from 2.3.0 to 2.4.0 And getting this error on initialization interpeteur
java.lang.IllegalArgumentException: Internal error: Failed to apply delegate: TfLiteGpuDelegate Init: MUL: Expected a 3D tensor of shape HxWxC or a 4D tensor of shape 1xHxWxC but got 98x8 TfLiteGpuDelegate Prepare: delegate is not initialized Node number 329 (TfLiteGpuDelegateV2) failed to prepare.
val tfliteOptions = Interpreter
.Options()
.setNumThreads(THREADS_COUNT)
.addDelegate(GpuDelegate())
Interpreter(loadModelFile(context), tfliteOptions)
The problem is somewhere in tensorflow-lite-gpu 2.4.0
If i'm using such configuration with older version all works well
implementation("org.tensorflow:tensorflow-lite:2.4.0")
implementation("org.tensorflow:tensorflow-lite-gpu:2.3.0")
2.4.0, 2.5.0, 2.6.0, 2.7.0, 2.8.0 Gpu delegates not working
Issue on GitHub https://github.com/tensorflow/tensorflow/issues/45845
Sample android project how to reproduce https://github.com/OleksandrGrument/GpuDelegateBugReproduce
Tflite Model https://github.com/OleksandrGrument/GpuDelegateBugReproduce/blob/master/app/src/main/assets/model.tflite
I have opened a thread on github but no results for 2 years, maybe someone have idea how to bypass this error by changing somehow tflite file
CodePudding user response:
I found a workaround for this issue, before converting to tflite I changed
tf.math.multiply(weights, var)
to
tf.linalg.matmul(weights, var, transpose_a=True)
Looks like from version 2.4.0 Gpu Delegate can't proceed this operation to multiply 2d arrays with tf.math.multiply.