【问题标题】:How do I format the response body of a request to the predict endpoint of a Google Cloud Platform API request如何将请求的响应正文格式化为 Google Cloud Platform API 请求的预测端点
【发布时间】:2021-04-28 01:30:50
【问题描述】:

在使用 AI Platform 组件时,我正在学习 GCP 上预制的教程。简而言之,它涉及使用 Kubeflow 和 Tensorflow Extended 来构建和部署一个完整的 ML 模型,以预测谁将成为 Chicago Taxi 数据集的大客户。一切都进展顺利,甚至可以部署并命中我的模型的预测端点,但是,我似乎无法正确获取请求正文或找到关于如何知道请求正文应该是什么样子的良好文档。下面我有:

  1. 来自 Kubeflow 中 SchemaGen 的模型
  2. 我用于训练的 data.csv 中的标头以及我从中提取的要测试的行
  3. 我在邮递员中使用的 curl 是错误的。

值得注意的是,该错误涉及预期的浮点数并获取字符串,但模型说它应该是浮点数。我想知道是否有人可以帮助我确定数据类型,requestBody 的排序,这样我就可以得到一个成功的预测。提前致谢!

来自 Kubeflow 的 SchemaGen:

csv 标头和数据行的副本: Pickup_community_area,fare,trip_start_month,trip_start_hour,trip_start_day,trip_start_timestamp,pickup_latitude,pickup_longitude,dropoff_latitude,dropoff_longitude,trip_miles,pickup_census_tract,dropoff_census_tract,payment_type,company,trip_seconds,dropoff_community_area,tips,big_tipper 60,27.05,10,2,3,1380593700,41.836150155,-87.648787952,,,12.6,,,现金,出租车加盟服务,1380,,0,0

卷曲:

curl --location --request POST 'https://ml.googleapis.com/v1/projects/ --header '授权:承载 --header '接受:应用程序/json'
--header '内容类型:应用程序/json'
--data-raw '{"instances":["Taxi Affiliation Services","","","","","27.05","Cash","",60,41.836150155,-87.648787952,0, 12.6,1380,3,2,10,1380593700]}'

回应: {"error": "预测失败:处理输入时出错:预期字符串,取而代之的是 27.05 类型的 'float'。"}

值得注意的是,如果我开始将所有浮点数和整数转换为字符串,它最终会给我一个无效的 requestbody 错误,这并不让我感到惊讶。

对于某些 cmets:如果我将单个 qoutes 添加到 double 中,并将空值更新为零:

请求正文:

{"instances":["Taxi Affiliation Services","'0'","'0'","'0'","'0'","'27.05'","Cash","'0'","'60,41.836150155'","'-87.648787952'","'0'","'12.6'","'1380'","'3'","'2'","'10'","'1380593700'"]}

回复:

{
"error": "Prediction failed: Error during model execution: <_MultiThreadedRendezvous of RPC that terminated with:\n\tstatus = StatusCode.INVALID_ARGUMENT\n\tdetails = \"Could not parse example input, value: 'Taxi Affiliation Services'\n\t [[{{node ParseExample/ParseExampleV2}}]]\"\n\tdebug_error_string = \"{\"created\":\"@1611579449.396545283\",\"description\":\"Error received from peer ipv4:127.0.0.1:8081\",\"file\":\"src/core/lib/surface/call.cc\",\"file_line\":1056,\"grpc_message\":\"Could not parse example input, value: 'Taxi Affiliation Services'\\n\\t [[{{node ParseExample/ParseExampleV2}}]]\",\"grpc_status\":3}\"\n>"

}

【问题讨论】:

  • 您是否尝试在双引号中添加简单引号?像这样"'27.05'"
  • 您学习了哪些 GCP 教程?当您按照教程进行操作时,您是否也进行了任何更改?只是为了让您的问题很容易被重现。
  • Guillaume 我尝试对所有数值使用双引号中的单引号进行格式化,并尝试在字段中添加 0 而不是将其留空。但仍然出现错误。
  • @RiccoD 我将本教程用于 kubeflow 管道和笔记本:tensorflow.org/tfx/tutorials/tfx/cloud-ai-platform-pipelines,这是我在设置模型时查看的文档:tensorflow.org/tfx/tutorials/tfx/cloud-ai-platform-pipelines
  • 在该教程中值得注意的是,gcp 会生成一个与教程一致的示例笔记本。如果一个步骤通过笔记本更新特定位置,它也会告诉您它应该被复制。虽然它可能是收费的!

标签: google-cloud-platform tensorflow-serving kubeflow-pipelines


【解决方案1】:

请尝试以下格式:-

{"instances":["\\"出租车加盟服务\\", , , , ,27.05,\\"现金\\", ,60,41.836150155,-87.648787952,0,12.6,1380,3, 2,10,1380593700"]}

您可以在此链接中查看每行编码为字符串值的 CSV 数据:- https://cloud.google.com/ai-platform/prediction/docs/reference/rest/v1/projects/predict#request-body-details

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2021-01-27
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 2021-07-22
    相关资源
    最近更新 更多