Issue with On-device Training using Shared Library

Hi everyone,

I’m currently running an on-device training experiment and need to use the TensorFlow Lite shared library through native-lib to implement this functionality. I have noticed that some ops require the use of the tensorflow-lite-select-tf-ops shared library.

I have imported libtensorflowlite_jni.so and libtensorflowlite_flex_jni.so, which I downloaded from Maven, into my project. My question is, how can I replace libtensorflowlite_jni.so with libtensorflowlite_flex_jni.so during training to support the ops that are not supported by libtensorflowlite_jni.so?

Thank you.

Hi @ODT_novice, place libtensorflowlite_flex_jni.so file in the location of libtensorflowlite_jni.so. The model will choose the file automatically. Thank you.

Dear Kiran_Sai_Ramineni,
Thank you for your response. Initially, I added these two libraries in the CMakeLists.txt file:
add_library( tensorflowlite_jni SHARED IMPORTED )
set_target_properties( tensorflowlite_jni PROPERTIES IMPORTED_LOCATION ${JNI_DIR}/${ANDROID_ABI}/libtensorflowlite_jni.so )

add_library( tensorflowlite_flex_jni SHARED IMPORTED )
set_target_properties( tensorflowlite_flex_jni PROPERTIES IMPORTED_LOCATION ${JNI_DIR}/${ANDROID_ABI}/libtensorflowlite_flex_jni.so )

I used the following command to invoke the train signature in my train.tflite file:
TfLiteSignatureRunnerInvoke(train_model_info.signature_info[2].runner);

However, I encountered the following error:
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.
Node number 1409 (FlexBroadcastGradientArgs) failed to prepare.

I am unable to use libtensorflowlite_flex_jni.so to support this operation.
If I directly remove libtensorflowlite_jni.so from my project, I encounter the following error:
undefined reference to `TfLiteSignatureRunnerInvoke’

I would like to know how to run these two libraries together if I want to use the C API for on-device training. How can I make libtensorflowlite_flex_jni.so support the operations that libtensorflowlite_jni.so does not support?

Thank you.

Hi Kiran_Sai_Ramineni, “modified by moderator”

Thank you for sharing your solution with @ODT_novice! It’s always helpful to see community members supporting each other with tips and insights.

For those who might encounter a similar issue, placing the libtensorflowlite_flex_jni.so file in the same location as libtensorflowlite_jni so can help the model automatically choose the appropriate file.

Your contribution is greatly appreciated!

Best regards,