shaqian / flutter_tflite

Flutter plugin for TensorFlow Lite
https://pub.dartlang.org/packages/tflite
MIT License
633 stars 408 forks source link

Interpreter busy exception after picking up an image in example project #47

Closed rstrelba closed 5 years ago

rstrelba commented 5 years ago

E/MethodChannel#tflite( 8556): Failed to handle method call E/MethodChannel#tflite( 8556): java.lang.IllegalArgumentException: Unsupported value: java.lang.RuntimeException: Interpreter busy E/MethodChannel#tflite( 8556): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294) E/MethodChannel#tflite( 8556): at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70) E/MethodChannel#tflite( 8556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:230) E/MethodChannel#tflite( 8556): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:175) E/MethodChannel#tflite( 8556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222) E/MethodChannel#tflite( 8556): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96) E/MethodChannel#tflite( 8556): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643) E/MethodChannel#tflite( 8556): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#tflite( 8556): at android.os.MessageQueue.next(MessageQueue.java:323) E/MethodChannel#tflite( 8556): at android.os.Looper.loop(Looper.java:142) E/MethodChannel#tflite( 8556): at android.app.ActivityThread.main(ActivityThread.java:6389) E/MethodChannel#tflite( 8556): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#tflite( 8556): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901) E/MethodChannel#tflite( 8556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:791) E/flutter ( 8556): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.RuntimeException: Interpreter busy, null)

shaqian commented 5 years ago

Hi, does this always happen or only under certain circumstances?

Thanks, Qian

anshdiv commented 5 years ago

Same thing happening for me also.

rstrelba commented 5 years ago

Hi, does this always happen or only under certain circumstances?

Thanks, Qian

Always

MrRefactoring commented 5 years ago

I think the initial error is:

E/eglCodecCommon( 9293): glUtilsParamSize: unknow param 0x000082da
E/eglCodecCommon( 9293): glUtilsParamSize: unknow param 0x000082da
E/MethodChannel#tflite( 9293): Failed to handle method call
E/MethodChannel#tflite( 9293): java.lang.IllegalArgumentException: Unsupported value: java.lang.NullPointerException: Attempt to invoke virtual method 'org.tensorflow.lite.Tensor org.tensorflow.lite.Interpreter.getInputTensor(int)' on a null object reference
E/MethodChannel#tflite( 9293):  at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/MethodChannel#tflite( 9293):  at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70)
E/MethodChannel#tflite( 9293):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:230)
E/MethodChannel#tflite( 9293):  at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:101)
E/MethodChannel#tflite( 9293):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#tflite( 9293):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#tflite( 9293):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/MethodChannel#tflite( 9293):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#tflite( 9293):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#tflite( 9293):  at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#tflite( 9293):  at android.app.ActivityThread.main(ActivityThread.java:6669)
E/MethodChannel#tflite( 9293):  at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#tflite( 9293):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/MethodChannel#tflite( 9293):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
D/EGL_emulation( 9293): eglMakeCurrent: 0xec104c00: ver 3 1 (tinfo 0xd611bdb0)
E/flutter ( 9293): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.NullPointerException: Attempt to invoke virtual method 'org.tensorflow.lite.Tensor org.tensorflow.lite.Interpreter.getInputTensor(int)' on a null object reference, null)
E/flutter ( 9293): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 9293): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter ( 9293): <asynchronous suspension>
E/flutter ( 9293): #2      Tflite.runModelOnImage (package:tflite/tflite.dart:28:27)
E/flutter ( 9293): <asynchronous suspension>
E/flutter ( 9293): #3      _MyAppState.recognizeImage (package:tflite_example/main.dart:161:37)
E/flutter ( 9293): <asynchronous suspension>
E/flutter ( 9293): #4      _MyAppState.predictImage (package:tflite_example/main.dart:68:15)
E/flutter ( 9293): <asynchronous suspension>
E/flutter ( 9293): #5      _MyAppState.predictImagePicker (package:tflite_example/main.dart:48:5)
E/flutter ( 9293): <asynchronous suspension>
E/flutter ( 9293): #6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter ( 9293): #7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter ( 9293): #8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 9293): #9      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 9293): #10     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
E/flutter ( 9293): #11     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter ( 9293): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter ( 9293): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 9293): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 9293): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 9293): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 9293): #17     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 9293): #18     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 9293): #19     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 9293): #20     _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter ( 9293): #21     _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
MrRefactoring commented 5 years ago

Try to start the application using the flutter run command and first select the desired model, and only then choose a picture. It's worked for me.

anshdiv commented 5 years ago

@MrRefactoring Thanks ...worked for me..

kidussc commented 3 years ago

Try to start the application using the flutter run command and first select the desired model, and only then choose a picture. It's worked for me.

Would you explain more

jtmuller5 commented 3 years ago

Make sure to call interpreter.close when you dispose the view containing it. If you don't the interpreter will stay alive and you'll see the busy error the next time you open the view.

suyogbargule commented 2 years ago

PlatformException (PlatformException(Failed to run model, Interpreter busy, java.lang.RuntimeException: Interpreter busy at sq.flutter.tflite.TflitePlugin$TfliteTask.(TflitePlugin.java:450) at sq.flutter.tflite.TflitePlugin$RunModelOnFrame.(TflitePlugin.java:545) at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:117) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320) at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8595) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) , null))

Abrmalkawi commented 2 years ago

Make sure to call interpreter.close when you dispose the view containing it. If you don't the interpreter will stay alive and you'll see the busy error the next time you open the view.

Hi, In which part of the code we should call interpreter.close().

Thanks

Genics85 commented 2 years ago

@Abrmalkawi did you get to know you have to put the interpreter.close();

ndongchrist commented 1 year ago

@Abrmalkawi did you get to know you have to put the interpreter.close();

How should i call thee interpreter.close()

priyadharshan-m commented 1 year ago

I too face the same problem when using runModelOnFrame() for real time object detection. Please some help to solve it

HarryProd commented 1 year ago

Pareil moi aussi, je suis confronté au même problème

GiannosP14 commented 5 months ago

Hi, did you find a solution for this?

priyadharshan20 commented 5 months ago

No I can't find a solution. Better move on to other libraries