You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

tflite_flutter调用GpuDelegateV2传参报错该如何解决?

错误原因
  • 你复制的是旧版官方文档示例,tflite_flutter v0.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 08:45:08