Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model does not work in release version #171

Open
syeds-git opened this issue Nov 7, 2020 · 5 comments
Open

Model does not work in release version #171

syeds-git opened this issue Nov 7, 2020 · 5 comments

Comments

@syeds-git
Copy link

syeds-git commented Nov 7, 2020

Hi,

I created a TFLite model using google's teachable machine. It is sort of working in the debug version of the flutter app. The only problem is that it finds a lot of false positives along with the true one's. But I think this could be an issue with the model itself. As long as it is finding anything I think the plugin is fine.

However, the model does not work when I use a signed release version of my app which I installed on my device using the bundletool. I don't get any crashes or any error's in the logs. My logs just print that no recognitions happened or return empty response from the tflite recognition code whereas it finds a lot more recognitions while in the debug mode. Can you please let me know what could have gone wrong between the debug and release version? also if there are any special steps that need to be carried out while in release?

Thanks

UPDATE

Digging further, I ran the app in profile mode and found following logs (Note: These only show up in profile mode so I am not sure how far it is from the release version. Also, I don't get these error when running in debug):

2020-11-08 20:04:34.623 4869-4940/com.flutterApp.gng I/flutter: PlatformException(Failed to run model, Attempt to invoke virtual method 'org.tensorflow.lite.Tensor org.tensorflow.lite.Interpreter.getInputTensor(int)' on a null object reference, java.lang.NullPointerException: Attempt to invoke virtual method 'org.tensorflow.lite.Tensor org.tensorflow.lite.Interpreter.getInputTensor(int)' on a null object reference
        at sq.flutter.tflite.TflitePlugin.feedInputTensor(TflitePlugin.java:326)
        at sq.flutter.tflite.TflitePlugin.feedInputTensorImage(TflitePlugin.java:371)
        at sq.flutter.tflite.TflitePlugin$RunModelOnImage.<init>(TflitePlugin.java:477)
        at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:102)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
        at android.os.MessageQueue.nativePollOnce(Native Method)
    	at android.os.Messag
...
2020-11-08 02:08:07.438 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.453 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.460 23087-23136/? I/qtaguid: Tagging socket 89 with tag 6b55000000000(439632) for uid -1 failed errno=-24
2020-11-08 02:08:07.460 23087-23136/? I/NetworkManagementSocketTagger: tagSocketFd(89, 439632, -1) failed with errno-24
2020-11-08 02:08:07.469 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.486 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.521 657-657/? I/chatty: uid=1000(system) /system/bin/surfaceflinger identical 2 lines
2020-11-08 02:08:07.540 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.542 22602-22654/com.flutterApp.gng I/flutter: Found 3 faces
2020-11-08 02:08:07.557 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.566 1449-2272/? W/StorageManager: getStorageLowBytes lowPercent : 5, lowBytes : 2861259366, maxLowBytes : 524288000
2020-11-08 02:08:07.577 22602-22654/com.flutterApp.gng I/flutter: PlatformException(Failed to run model, Interpreter busy, java.lang.RuntimeException: Interpreter busy
        at sq.flutter.tflite.TflitePlugin$TfliteTask.<init>(TflitePlugin.java:427)
        at sq.flutter.tflite.TflitePlugin$RunModelOnImage.<init>(TflitePlugin.java:465)
        at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:102)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:325)
        at android.os.Looper.loop(Looper.java:142)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1
2020-11-08 02:08:07.588 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.608 22602-22654/com.flutterApp.gng I/flutter: PlatformException(Failed to run model, Interpreter busy, java.lang.RuntimeException: Interpreter busy
        at sq.flutter.tflite.TflitePlugin$TfliteTask.<init>(TflitePlugin.java:427)
        at sq.flutter.tflite.TflitePlugin$RunModelOnImage.<init>(TflitePlugin.java:465)
        at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:102)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:325)
        at android.os.Looper.loop(Looper.java:142)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1
2020-11-08 02:08:07.622 657-657/? I/HWComposer: getActiveConfigs: Attempted to access invalid display -1
2020-11-08 02:08:07.641 22602-22654/com.flutterApp.gng I/flutter: PlatformException(Failed to run model, Interpreter busy, java.lang.RuntimeException: Interpreter busy
        at sq.flutter.tflite.TflitePlugin$TfliteTask.<init>(TflitePlugin.java:427)
        at sq.flutter.tflite.TflitePlugin$RunModelOnImage.<init>(TflitePlugin.java:465)
        at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:102)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:325)
        at android.os.Looper.loop(Looper.java:142)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1

As I don't see the behavior in debug mode, I am still confused on what is going on in the app when running the release version.

@crisfox
Copy link

crisfox commented Feb 23, 2021

Hello! Could you find out what the problem is?

@prakashssp077
Copy link

can anyone solved this problem?

@prakashssp077
Copy link

i am getting error like

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(Failed to run model, null, java.nio.BufferOverflowException
E/flutter (30792): at java.nio.Buffer.nextPutIndex(Buffer.java:542)
E/flutter (30792): at java.nio.DirectByteBuffer.putFloat(DirectByteBuffer.java:802)
E/flutter (30792): at sq.flutter.tflite.TflitePlugin.feedInputTensor(TflitePlugin.java:349)
E/flutter (30792): at sq.flutter.tflite.TflitePlugin.feedInputTensorImage(TflitePlugin.java:371)
E/flutter (30792): at sq.flutter.tflite.TflitePlugin$RunModelOnImage.(TflitePlugin.java:477)
E/flutter (30792): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:102)
E/flutter (30792): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (30792): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter (30792): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter (30792): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (30792): at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter (30792): at android.os.Looper.loop(Looper.java:165)
E/flutter (30792): at android.app.ActivityThread.main(ActivityThread.java:6810)
E/flutter (30792): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (30792): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/flutter (30792): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
E/flutter (30792): , null)

@Theunodb
Copy link

Theunodb commented May 5, 2021

Also having this issue. It runs fine on the simulator, and on device when in debug mode. But when you run in release mode / upload to the store nothing is detected

@klivin
Copy link

klivin commented Sep 28, 2021

I had this same issue, and I found that assertions are turned off in release mode, so if you were following an example from Stack overflow that placed the model loading in an assertion as in:

 assert(await Tflite.loadModel(
              model: modelFile.path,
              labels: fullPath,
              numThreads: 1, // defaults to 1
              isAsset:
                  false, // defaults to true, set to false to load resources outside assets
              useGpuDelegate:
                  false // defaults to false, set to true to use GPU delegate
              ) ==
          'success');

This will not work in release mode

Change to something like and surround with try catch:

      var result = await Tflite.loadModel(
          model: modelFile.path,
          labels: fullPath,
          numThreads: 1, // defaults to 1
          isAsset:
              false, // defaults to true, set to false to load resources outside assets
          useGpuDelegate:
              false // defaults to false, set to true to use GPU delegate
          );
      return result;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants