【问题标题】:"error": "Prediction failed: unknown error.""error": "预测失败:未知错误。"
【发布时间】:2020-01-12 10:42:56
【问题描述】:

我正在请求对经过训练的模型(使用线性学习算法创建的模型)进行在线预测并收到“错误”:“预测失败:未知错误。”

这是我在 Google AI 平台上的第一个 ML 模型。模型训练成功,训练数据、验证数据和测试数据在输出文件夹中看起来都不错。但是当我尝试通过传递输入 JSON 来测试模型时,我得到了这个错误。我一直在寻找类似的其他帖子,但找不到成功预测的解决方案。

artifact 文件夹中的metadata.json 看起来像

{
    "feature_columns": {
    "col_0": {
      "mapping": {
        "0": 0, 
        "1": 1, 
        "10": 10, 
        "2": 2, 
        "3": 3, 
        "4": 4, 
        "5": 5, 
        "6": 6, 
        "7": 7, 
        "8": 8, 
        "9": 9
      }, 
      "mode": "0", 
      "num_category": 11, 
      "treatment": "identity", 
      "type": "categorical"
    }, 
    "col_1": {
      "mapping": {
        "0": 0, 
        "1": 1, 
        "10": 10, 
        "2": 2, 
        "3": 3, 
        "4": 4, 
        "5": 5, 
        "6": 6, 
        "7": 7, 
        "8": 8, 
        "9": 9
      }, 
      "mode": "4", 
      "num_category": 11, 
      "treatment": "identity", 
      "type": "categorical"
    }
  }, 
  "target_algorithm": "TensorFlow", 
  "target_column": {
    "type": "regression"
  }
}

我为测试预测传递的输入 JSON 是 { “实例”:[5,5] }

该模型预计将 2 个输入特征相加并给出 10 的结果

你能告诉错误在哪里吗?

【问题讨论】:

    标签: google-cloud-ml


    【解决方案1】:

    如果您使用 gcloud 发送文件,请执行以下操作:

     {"col_0": "5", "col_1": "5" }
    

    如果您通过其他客户端发送大量实例,请执行以下操作:

    { 
      "instances": [
        {"col_0": "5", "col_1": "5" },
        {"col_0": "3", "col_1": "2" }
      ]
    } 
    

    【讨论】:

    • 您好 Lak,感谢您的回答。当我尝试使用上述方法时,我收到此错误消息 { "error": "Prediction failed: Unexpected tensor name: col_0" }
    • 你好@Lak,我使用的是google AI平台提供的“Test & Use”界面。当我打开模型版本时,会出现此“测试和使用”选项卡以进行在线预测。
    • 看起来您的模型在其输入中不期望 col_0。在本地运行时模型的输入是什么?stackoverflow.com/questions/51930002/…
    【解决方案2】:

    Lak 的回答很好,而且做得很好。
    尽管我的输入数据不同,但我得到了相同的错误,尽管本地预测成功。以下是对我有帮助的另外两件事。

    运行 !gcloud ai-platform predict --help 以详细了解您的输入应如何格式化以及在拨打电话时使用哪个标志。

    使用!saved_model_cli show --dir ${YOUR_LOCAL_MODEL_PATH} --all 检查模型以检查输入的名称。验证它们实际上是(在您的情况下)inputs[col_0]inputs[col_1]

    使用您上面提到的“测试和使用”界面(以及在此SO answer 中)可以更快地进行实验。

    【讨论】:

      猜你喜欢
      • 2017-11-19
      • 1970-01-01
      • 2021-05-03
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多