am15h / tflite_flutter_plugin

TensorFlow Lite Flutter Plugin
https://pub.dev/packages/tflite_flutter
Apache License 2.0
507 stars 353 forks source link

iOS MetalDelegate exception #152

Open CaptainDario opened 3 years ago

CaptainDario commented 3 years ago

Hello,

when I try to use the MetalDelegate on an iPad pro 12.9 2017 I am getting an exception. With creating an interpreter like this:

    final gpuDelegate = GpuDelegate(
      options: GpuDelegateOptions(
          allowPrecisionLoss: true, waitType: TFLGpuDelegateWaitType.active),
    );
    var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegate);
    return await Interpreter.fromAsset(_interpreterAssetPath,
        options: interpreterOptions);

The following exception is thrown

Unhandled Exception: Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, TFLGpuDelegateCreate): symbol not found)

The full output:

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Failed to lookup symbol (dlsym(RTLD_DEFAULT, TFLGpuDelegateCreate): symbol not found)

#0      DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:31:29)
#1      tflGpuDelegateCreate
package:tflite_flutter/…/delegates/metal_delegate.dart:18
#2      tflGpuDelegateCreate (package:tflite_flutter/src/bindings/delegates/metal_delegate.dart)
package:tflite_flutter/…/delegates/metal_delegate.dart:1
#3      new GpuDelegate
package:tflite_flutter/…/delegates/metal_delegate.dart:25
#4      DrawingInterpreter._gpuInterpreterIOS
package:da_kanji_mobile/…/core/DrawingInterpreter.dart:292
#5      DrawingInterpreter._initInterpreterIOS
package:da_kanji_mobile/…/core/DrawingInterpreter.dart:262
<asynchronous suspension>
#6      DrawingInterpreter.init
package:da_kanji_mobile/…/core/DrawingInterpreter.dart:102
<asynchronous suspension>

Any help with this would be greatly appreciated.

@am15h the README is out of date in regards to creating a Metal delegate interpreter. The parameters I am using became optional.

CaptainDario commented 3 years ago

As mentioned in #100 one needs to build TF Lite for iOS from source to get the MetalDelegate working. However it is not possible for me to build TF Lite from source.

@am15h would it be possible for you to provide a Metal enabled version for this plugin?

CaptainDario commented 3 years ago

Maybe it would be nice to include that in the README too.

Like:

iOS

Pub-Cache folder location: (ref)

~/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-<plugin-version>/ios/ (Linux/ Mac)
%LOCALAPPDATA%\Pub\Cache\hosted\pub.dartlang.org\tflite_flutter-<plugin-version>\ios\ (Windows)