tflite_flutter_plugin icon indicating copy to clipboard operation
tflite_flutter_plugin copied to clipboard

iOS MetalDelegate exception

Open CaptainDario opened this issue 4 years ago • 2 comments

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 avatar Sep 10 '21 22:09 CaptainDario

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 avatar Sep 13 '21 18:09 CaptainDario

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

Like:

iOS

  • Download TensorFlowLiteC.framework (CPU inference only!).
    • If you want Metal Delegate support or want to build a custom version of tensorflow, follow instructions in wiki.
  • run dart pub get
  • Place the TensorFlowLiteC.framework in the pub-cache folder of this package.

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)

CaptainDario avatar Sep 13 '21 18:09 CaptainDario