shaqian / flutter_tflite

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

NullPointerException in Android Release mode #157

Open VadymPinchuk opened 3 years ago

VadymPinchuk commented 3 years ago

Issue occurs after models loaded

      assert(await Tflite.loadModel(
            model: modelsFile.path,
            labels: labelsFile.path,
            numThreads: 2,
            isAsset: false,
          ) ==
          'success');

Files here are loaded from storage and pushed to Tflite. And on first detection - issue occurs.

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
I/flutter (25062):      at sq.flutter.tflite.TflitePlugin.feedInputTensor(TflitePlugin.java:326)
I/flutter (25062):      at sq.flutter.tflite.TflitePlugin.feedInputTensorImage(TflitePlugin.java:371)
I/flutter (25062):      at sq.flutter.tflite.TflitePlugin.detectObjectOnImage(TflitePlugin.java:565)
I/flutter (25062):      at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:120)
I/flutter (25062):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
I/flutter (25062):      at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
I/flutter (25062):      at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
I/flutter (25062):      at android.os.MessageQueue.nativePollOnce(Native Method)
I/flutter (25062):      at android.os.MessageQu
carnevalli commented 3 years ago

Please, check if you've added these lines inside android block in android/app/build.gradle

    aaptOptions {
        noCompress 'tflite'
        noCompress 'lite'
    }
crisfox commented 3 years ago

Find the solution? The same thing happens to me in the release compilation, only in production

VadymPinchuk commented 1 year ago

Please, check if you've added these lines inside android block in android/app/build.gradle

    aaptOptions {
        noCompress 'tflite'
        noCompress 'lite'
    }

Yes this was added

Sk-Mattes commented 4 months ago

Anyone found the solution?

aaptOptions { noCompress 'tflite' noCompress 'lite' } This doesnt seem to fix the Problem at least for me.

Kind regards!