Node number failed to prepare with nn-device training in Android

I have a TFLite model that is designed for on-device training, with signatures including restore, train, and save. I have successfully run it using the Java task in my own app.

However, when I try to run it using the TensorFlow Lite shared library that I downloaded from this link: Maven Central Repository Search, I encounter an error.

For the restore and train signatures, I followed these steps: set input tensors → TfLiteSignatureRunnerInvoke → read output tensors. But the error log indicates that the Select TensorFlow op(s) are not supported by this interpreter when running TfLiteSignatureRunnerInvoke.

Here is the 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, this can be resolved by adding the ‘org.tensorflow:tensorflow-lite-select-tf-ops’ dependency. See instructions: عملگرهای TensorFlow را انتخاب کنید  |  TensorFlow Lite Node number 151 (FlexRestore) failed to prepare.”

I would like to know if there is any other method to address this issue. Does the TensorFlow Lite C API support on-device training for restoring weights and training a new model?

Thank you very much in advance.

@ODT_novice,

Welcome to the Tensorflow Forum,

As per this blog post, on Android, Tensorflow Lite on-device training can be performed using either Java or C++ APIs.

Will using the C++ API effects your use case?

Thank you!

Dear chunduriv,
Thank you for your response.

I have referred to this blog and implemented on-device training on my mobile device.
If I use the Java API to invoke my train.tflite, I can successfully perform actions such as restoring weights, training, and saving weights.
However, if I use JNI/native-lib to invoke the official pre-built C API shared library that I downloaded, I encounter the following error: “TensorFlow Lite Node number 151 (FlexRestore) failed to prepare.”
This prevents me from using actions like restoring weights, training, and saving weights properly.
It seems that the C API does not support the “restore weight” operation.
I suspect that only libtensorflowlite_flex_jni.so supports this operation, but I don’t know how to automatically invoke the operations inside libtensorflowlite_flex_jni.so when I discover that libtensorflowlite_jni.so does not support it.

Thank you!!