pytorch_lite icon indicating copy to clipboard operation
pytorch_lite copied to clipboard

Error using Isolates (Multithreading)

Open tnghieu opened this issue 1 year ago • 13 comments

Is it possible to use pytorch_lite in isolates for running inference? I'm trying to split up the work on separate threads to speed up the process.

[ERROR:flutter/runtime/dart_isolate.cc(1097)] Unhandled exception: Bad state: The BackgroundIsolateBinaryMessenger.instance value is invalid until BackgroundIsolateBinaryMessenger.ensureInitialized is executed. #0 BackgroundIsolateBinaryMessenger.instance (package:flutter/src/services/_background_isolate_binary_messenger_io.dart:27:7) #1 _findBinaryMessenger (package:flutter/src/services/platform_channel.dart:145:42) #2 BasicMessageChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:192:56) #3 BasicMessageChannel.send (package:flutter/src/services/platform_channel.dart:206:38) #4 ModelApi.getImagePredictionListObjectDetection (package:pytorch_lite/pigeon.dart:319:52) #5 ModelObjectDetection.getImagePredictionList (package:pytorch_lite/pytorch_lite.dart:525:30) #6 ModelObjectDetection.getImagePrediction (package:pytorch_lite/pytorch_lite.dart:455:52) #7 _InferencePageState.processImageBatch (package:sharkeye/inference_page.dart:120:38) #8 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:300:17) #9 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

ChatGPT's response to this error: 'The PytorchLite plugin is attempting to use platform channels (binary messenger) inside an isolate, which is not supported by default in Flutter.'

tnghieu avatar Oct 23 '23 16:10 tnghieu