tflite_flutter调用GpuDelegateV2传参报错该如何解决?
错误原因
- 你复制的是旧版官方文档示例,
tflite_flutterv0.10.0及以上版本中,GpuDelegateOptionsV2的构造函数已调整为全命名参数形式,不再支持位置参数传入配置,所以会抛出参数数量不匹配的异常。
解决方案
把GpuDelegateOptionsV2的参数全部改为指定参数名的形式传入即可,修正后的完整代码如下:
final gpuDelegateV2 = GpuDelegateV2( options: GpuDelegateOptionsV2( isPrecisionLossAllowed: false, inferenceUsage: TfLiteGpuInferenceUsage.fastSingleAnswer, inferencePriority1: TfLiteGpuInferencePriority.minLatency, inferencePriority2: TfLiteGpuInferencePriority.auto, inferencePriority3: TfLiteGpuInferencePriority.auto, )); var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegateV2); final interpreter = await Interpreter.fromAsset('your_model.tflite', options: interpreterOptions);
- 如果不需要自定义GPU推理优先级、精度策略,也可以直接使用默认配置简化代码:
final gpuDelegateV2 = GpuDelegateV2(); var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegateV2); final interpreter = await Interpreter.fromAsset('your_model.tflite', options: interpreterOptions);
内容的提问来源于stack exchange,提问作者Mudasir Habib
相关产品推荐
相关产品推荐

