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

How can I load a tflite model using Isolate? #214

Open
app-chain-hagio opened this issue May 7, 2024 · 1 comment
Open

How can I load a tflite model using Isolate? #214

app-chain-hagio opened this issue May 7, 2024 · 1 comment

Comments

@app-chain-hagio
Copy link

app-chain-hagio commented May 7, 2024

Since the screen drawing becomes unstable during loading, I am thinking of loading the model using Isolate.

I got an error with the code below. 
thanks.

[ERROR:flutter/runtime/dart_isolate.cc(1107)] Unhandled exception:
Invalid argument: <- _interpreter in Instance of 'Interpreter' (from package:tflite_flutter/src/interpreter.dart)

Future<dynamic> spawnAndReceive(File filename) async {
    final resultPort = ReceivePort();
    await Isolate.spawn(_readTensorModel, [resultPort.sendPort, filename]);
    return (await resultPort.first);
  }

void _readTensorModel(List<dynamic> args) async {
    SendPort responsePort = args[0];
    File fileName = args[1];

    var itp = Interpreter.fromFile(fileName);
    Isolate.exit(responsePort, itp);
  }
@app-chain-hagio
Copy link
Author

app-chain-hagio commented May 8, 2024

I changed Isolate.exit to

Isolate.exit(responsePort, itp.address);

int address = isolateTask.spawnAndReceive(dataFile);
interpreter = Interpreter.fromAddress(address);

and after this, I can get Instance using address.
it works, but, Does this make sense for processing distribution?

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

1 participant