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

TensorFlow Lite模型推理报错求助:输入参数不匹配问题

解决TFLite签名推理的参数错误问题

首先,你遇到的问题核心是错误传入多余参数,且使用了模型签名中不存在的输入参数名。以下是具体解决步骤:

  1. 查看模型签名的输入输出名称
    在调用签名运行器前,先打印模型的签名列表,确认实际的输入参数名(不一定是x):

    interpreter = tf.lite.Interpreter('tflite_model')
    print(interpreter.get_signature_list())
    

    输出示例可能类似:

    {'serving_default': {'inputs': ['input_1'], 'outputs': ['predictions']}}
    

    这里的input_1就是你需要传入的参数名,predictions是输出键名。

  2. 使用正确的参数名调用签名运行器
    不需要传入shape和dtype参数(签名已预先定义输入的形状和数据类型),只需传入对应名称的输入张量:

    my_signature = interpreter.get_signature_runner()
    # 替换成你从签名列表中得到的输入名称
    output = my_signature(input_1=x)
    # 替换成对应的输出名称
    print(output['predictions'])
    

错误原因说明

  • 最初传入x=x, shape=x.shape, dtype=tf.float32属于多传了2个参数,而模型签名仅定义了1个输入,因此触发expected 1 vs provided 3的错误。
  • 用my_signature(x=x)提示参数无效,是因为你的TFLite模型签名中并没有名为x的输入参数,输入名由原Keras模型的输入层名称决定(比如默认的input_1)。

内容的提问来源于stack exchange,提问作者Olli

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 09:40:28