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

[WiP] [Android] Switch to upstream TFlite binaries instead of precompiled ones #42

Closed
wants to merge 7 commits into from

Conversation

vishnukvmd
Copy link

Inspiration: yy1300326388/tflite_flutter_plugin

Status

The example app runs without any errors.

But once GPU delegates are enabled by modifying _loadModel() within classifier.dart,

void _loadModel() async {
  final gpuDelegateV2 = GpuDelegateV2();
  final options = InterpreterOptions()..addDelegate(gpuDelegateV2);
  _interpreter =
      await Interpreter.fromAsset(_modelFile, options: options);
  print('Interpreter loaded successfully');
}

this fails with the following error:

E/tflite  (14679): TfLiteGpuDelegate Init: [GL_INVALID_OPERATION]: The specified operation is not allowed in the current state.
I/tflite  (14679): Created 0 GPU delegate kernels.
E/tflite  (14679): TfLiteGpuDelegate Prepare: delegate is not initialized
E/tflite  (14679): Node number 6 (TfLiteGpuDelegateV2) failed to prepare.
E/tflite  (14679): Restored original execution plan after delegate application failure.
E/flutter (14679): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Unable to create interpreter.
E/flutter (14679): #0      checkArgument (package:quiver/check.dart:45:5)
E/flutter (14679): #1      new Interpreter._create (package:tflite_flutter/src/interpreter.dart:58:5)
E/flutter (14679): #2      new Interpreter.fromBuffer (package:tflite_flutter/src/interpreter.dart:109:37)
E/flutter (14679): #3      Interpreter.fromAsset (package:tflite_flutter/src/interpreter.dart:127:24)
E/flutter (14679): <asynchronous suspension>
E/flutter (14679): #4      Classifier._loadModel (package:tflite_flutter_plugin_example/classifier.dart:56:9)
E/flutter (14679): <asynchronous suspension>

Any help would be much appreciated :)

@google-cla
Copy link

google-cla bot commented May 6, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@PaulTR
Copy link
Collaborator

PaulTR commented May 6, 2023

Looks like this relates to issue #16.

This is a huge help. Thanks @vishnukvmd! Looking forward to when it's ready.

@@ -43,7 +43,10 @@ class Classifier {

void _loadModel() async {
// Creating the interpreter using Interpreter.fromAsset
_interpreter = await Interpreter.fromAsset(_modelFile);
final gpuDelegateV2 = GpuDelegateV2();
final options = InterpreterOptions()..addDelegate(gpuDelegateV2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo on the double dots?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cascade notation, compiles as expected

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I'll undo the changes in this file once the GPU delegates are working. Keeping this around so it's easy to reproduce the issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL - Thanks! Still learning Dart (I've been doing Android for 12 years) since I think Flutter has a lot of advantages, but also a little behind where I'd like to be :)

@vishnukvmd
Copy link
Author

@PaulTR The GPU delegate issue is a regression introduced by these changes, and I don't quite understand what's going on. If you could help or loop in someone who might know what's amiss, that would be great!

@PaulTR
Copy link
Collaborator

PaulTR commented May 22, 2023

Thanks vishnukvmd! I think this change is resolved with #49, so closing this out. I appreciate your work though!

@PaulTR PaulTR closed this May 22, 2023
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

Successfully merging this pull request may close these issues.

2 participants