【问题标题】:GpuDelegateV2 Tflite won't accept any parametersGpuDelegateV2 Tflite 不接受任何参数
【发布时间】:2021-12-20 23:50:33
【问题描述】:

我正在使用 tflite_flutter 包来加载 tflite 模型。我通过安装包

flutter pub 添加 tflite_flutter

sh install.sh -d 用于使用 GpuDelegateV2

按照我从文档中复制的示例代码。

final gpuDelegateV2 = GpuDelegateV2(
    options: GpuDelegateOptionsV2(
    false,
    TfLiteGpuInferenceUsage.fastSingleAnswer,
    TfLiteGpuInferencePriority.minLatency,
    TfLiteGpuInferencePriority.auto,
    TfLiteGpuInferencePriority.auto,
));

var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegateV2);
final interpreter = await Interpreter.fromAsset('your_model.tflite',
    options: interpreterOptions);

但它给出了异常位置参数过多:预期为 0,但找到了 5。 尝试删除额外的位置参数,或指定命名参数的名称 linter 还在“false”参数上给出了红线。

【问题讨论】:

    标签: flutter tensorflow tensorflow-lite


    【解决方案1】:

    可能文档没有更新,因为构造函数只允许命名参数所以代码会这样

    getModel() async {
      final gpuDelegateV2 = GpuDelegateV2(
        options: GpuDelegateOptionsV2(
          isPrecisionLossAllowed: false,
          inferencePriority1: TfLiteGpuInferencePriority.minLatency,
          inferencePriority2: TfLiteGpuInferencePriority.auto,
          inferencePriority3: TfLiteGpuInferencePriority.auto,
        ),
      );
    
      var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegateV2);
    final interpreter = await Interpreter.fromAsset('your_model.tflite',
    options: interpreterOptions);
    

    现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-23
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2020-07-29
      • 2013-04-19
      • 2017-10-23
      相关资源
      最近更新 更多