TensorFlow Lite in Play Services, app is crashing when creating interpreter
It seems that the crash is happening in the TensorFlow Lite GPU delegate while trying to create an interpreter. One potential solution is to disable the GPU delegate and only use the CPU delegate. You can do this by removing the following line of code:

arduino
Copy code
.addDelegateFactory(new GpuDelegateFactory())
If the issue persists, you could try updating your TensorFlow Lite in Play Services SDK to the latest version to see if the problem has been resolved in a newer release.

Additionally, you can check if there are any compatibility issues between the Samsung a13 device and the TensorFlow Lite GPU delegate by checking the device's specifications and the minimum requirements for the GPU delegate. You may also want to check if any other apps on the device are experiencing similar crashes and try to isolate the issue by running the app on other devices. Finally, you could try reaching out to the TensorFlow community forums for more help and guidance. Hi @sandeep5193 

Sorry for delayed response.

We can enable the GPU delegate option in the TFlite initialization by
```
TfLite.initialize(context,
      TfLiteInitializationOptions.builder()
       .setEnableGpuDelegateSupport(true)
       .build());
```
before adding `.addDelegateFactory(new GpuDelegateFactory())`

Please refer [this](https://www.tensorflow.org/lite/android/play_services#gpu_with_interpreter_apis) instructions on using GPU delegate.
 
If the issue still persists, could you please provide a standalone code to reproduce this issue?

Thanks. The code I have mentioned is working fine for some time now. All of a
sudden it started crashing on few devices, without any changes in our code. You still think by
changing initialisation steps you have mentioned will solve the problem?

On Mon, 17 Apr, 2023, 5:25 pm pjpratik, ***@***.***> wrote:

> Hi @sandeep5193 <https://github.com/sandeep5193>
>
> Sorry for delayed response.
>
> We can enable the GPU delegate option in the TFlite initialization by
>
> TfLite.initialize(context,
>       TfLiteInitializationOptions.builder()
>        .setEnableGpuDelegateSupport(true)
>        .build());
>
> before adding .addDelegateFactory(new GpuDelegateFactory())
>
> Please refer this
> <https://www.tensorflow.org/lite/android/play_services#gpu_with_interpreter_apis>
> instructions on using GPU delegate.
>
> If the issue still persists, could you please provide a standalone code to
> reproduce this issue?
>
> Thanks.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/60313#issuecomment-1511200353>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABHUPVFGJFMGNNAX76YIALLXBUVTDANCNFSM6AAAAAAW5BL6IQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
 Hi @sandeep5193 

Was it working fine with GPU delegate on few cases? 

I was checking if the the GPU delegate is not initialized that maybe causing the issue.

Can you provide a reproducible code to better understand and investigate the issue.

Thanks. hi @pjpratik

it was working very well in all devices. all of a sudden we started receiving this error in production, for few devices, exact numbers you can read in my first post. so we had to stop it.

we are not able to reproduce this in our development devices, but code mentioned in the original post is the point of crash. Given that it says [libtensorflowlite_jni_gms_client.so], this is beyond my understanding.  @sachinprasadhs can this be assigned to the TFLite in GMS core team? Hi, we have identified a compatibility issue between the TFLite runtime module and the GPU delegate module that might be the cause of this crash. The good news is, we are already in the process of rolling out an update that should fix the issue. I will post an update on this bug once the rollout is complete. @sheepmaster can I downgrade my tflite version to remedy this in the short term?
 We have finished the rollout, so devices should pick up the fix automatically. If you still encounter crashes, please let us know (ideally by filing a new bug, so we can distinguish different issues). Thanks! This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60313">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60313">No</a>

**System information**
- Android Device information: samsung a13 (5793 events, 31% of total events), samsung m11q, Redmi olivewood, samsung j6lte, samsung m13, samsung j7velte, samsung on7xelte
- TensorFlow Lite in Play Services SDK version: play-services-tflite-java:16.0.1, play-services-tflite-gpu:16.1.0
- Google Play Services version: don't know, never happened in dev devices.

**Standalone code to reproduce the issue**
```
InterpreterApi.create(new File(modelFile),
                        new InterpreterApi.Options()
                                .setRuntime(TfLiteRuntime.FROM_SYSTEM_ONLY)
                                .addDelegateFactory(new GpuDelegateFactory()));
```

**Any other info / logs**
We have started receiving this crash from 23 March 2023, app was updated a month ago before this(21st feb). When we stopped using GPU Delegate, toggled through Firebase Remote Config, the error went away.

Samsung a13 device alone has registered 5793 crashes, which is 31% of total events, based on Play Store Console. title in the console is "[libtensorflowlite_jni_gms_client.so] Java_com_google_android_gms_tflite_NativeInterpreterWrapper_createInterpreter"

backtrace:
```
  #00  pc 0x000000000015643a  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #01  pc 0x0000000000156415  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #02  pc 0x0000000000059961  /data/user_de/0/com.google.android.gms/app_chimera/m/000000bd/dl-TfliteGpuDynamite.optional_231015100300.apk
  #03  pc 0x0000000000159279  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #04  pc 0x000000000014f4bf  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #05  pc 0x000000000014da61  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #06  pc 0x000000000014d8db  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #07  pc 0x0000000000036181  /data/user_de/0/com.google.android.gms/app_chimera/m/0000003c/dl-TfliteDynamiteDynamite.integ_224210505100300.apk
  #08  pc 0x000000000001b477  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/lib/arm/libtensorflowlite_jni_gms_client.so
  #09  pc 0x000000000001a609  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/lib/arm/libtensorflowlite_jni_gms_client.so
  #10  pc 0x000000000001a673  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/lib/arm/libtensorflowlite_jni_gms_client.so
  #11  pc 0x000000000001abc1  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/lib/arm/libtensorflowlite_jni_gms_client.so
  #12  pc 0x0000000000017d61  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/lib/arm/libtensorflowlite_jni_gms_client.so (Java_com_google_android_gms_tflite_NativeInterpreterWrapper_createInterpreter+452)
  #13  pc 0x000000000014e2b5  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.odex (art_jni_trampoline+100)
  #14  pc 0x00000000000edf38  /apex/com.android.art/lib/libart.so (nterp_helper+2728)
  #15  pc 0x00000000009af384  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.android.gms.tflite.NativeInterpreterWrapper.zzl+528)
  #16  pc 0x00000000000ee688  /apex/com.android.art/lib/libart.so (nterp_helper+4600)
  #17  pc 0x00000000009af08e  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.android.gms.tflite.NativeInterpreterWrapper.<init>+86)
  #18  pc 0x00000000000edf80  /apex/com.android.art/lib/libart.so (nterp_helper+2800)
  #19  pc 0x00000000009afbd2  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.android.gms.tflite.zzd.<init>+18)
  #20  pc 0x00000000000edf80  /apex/com.android.art/lib/libart.so (nterp_helper+2800)
  #21  pc 0x00000000009aef44  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.android.gms.tflite.InterpreterFactoryImpl.create+24)
  #22  pc 0x00000000000ee92c  /apex/com.android.art/lib/libart.so (nterp_helper+5276)
  #23  pc 0x000000000040f87e  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (androidx.appcompat.widget.a0.b+230)
  #24  pc 0x00000000000ed4c8  /apex/com.android.art/lib/libart.so (nterp_helper+56)
  #25  pc 0x00000000009b6ce0  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.firebase.samples.apps.mlkit.NsfwImageProcessor.createInterpreter+104)
  #26  pc 0x00000000000edf80  /apex/com.android.art/lib/libart.so (nterp_helper+2800)
  #27  pc 0x00000000009b6d0a  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.firebase.samples.apps.mlkit.NsfwImageProcessor.lambda$new$0)
  #28  pc 0x00000000000edf80  /apex/com.android.art/lib/libart.so (nterp_helper+2800)
  #29  pc 0x00000000009b6bbc  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.google.firebase.samples.apps.mlkit.NsfwImageProcessor.a)
  #30  pc 0x00000000000ed4c8  /apex/com.android.art/lib/libart.so (nterp_helper+56)
  #31  pc 0x00000000004123f0  /data/app/~~RdHSBgE6dMlsRCnHjLYXZw==/com.example-Z6wg41mIr1QI0UuN7e6zkQ==/oat/arm/base.vdex (com.applovin.exoplayer2.b.a0.run+44)
  #32  pc 0x0000000000c964b7  /data/misc/apexdata/com.android.art/dalvik-cache/arm/boot.oat (android.os.Handler.dispatchMessage+70)
  #33  pc 0x0000000000c99fb7  /data/misc/apexdata/com.android.art/dalvik-cache/arm/boot.oat (android.os.Looper.loopOnce+886)
  #34  pc 0x0000000000c99b5b  /data/misc/apexdata/com.android.art/dalvik-cache/arm/boot.oat (android.os.Looper.loop+1034)
  #35  pc 0x0000000000c989bd  /data/misc/apexdata/com.android.art/dalvik-cache/arm/boot.oat (android.os.HandlerThread.run+1748)
  #36  pc 0x00000000003bdbd5  /apex/com.android.art/lib/libart.so (art_quick_invoke_stub_internal+68)
  #37  pc 0x00000000003bd677  /apex/com.android.art/lib/libart.so (void art::quick_invoke_reg_setup<false>(art::ArtMethod*, unsigned int*, unsigned int, art::Thread*, art::JValue*, char const*) (.__uniq.192663596067446536341070919852553954320.llvm.16200230356545185596)+158)
  #38  pc 0x0000000000288f1d  /apex/com.android.art/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+136)
  #39  pc 0x00000000003128a9  /apex/com.android.art/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*) (.__uniq.245181933781456475607640333933569312899.llvm.1951482298021755071)+40)
  #40  pc 0x00000000003127b5  /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, jvalue const*)+164)
  #41  pc 0x000000000033dc8b  /apex/com.android.art/lib/libart.so (art::JValue art::InvokeVirtualOrInterfaceWithJValues<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, jvalue const*)+42)
  #42  pc 0x00000000002f0bad  /apex/com.android.art/lib/libart.so (art::Thread::CreateCallback(void*)+424)
  #43  pc 0x00000000000afc5f  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
  #44  pc 0x0000000000065ef1  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)

```

