如何格式化对 Google Cloud Platform API 请求的预测端点的请求的响应正文

问题描述

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

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

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

来自 Kubeflow 的 SchemaGen:

enter image description here

csv 标题和数据行的副本: 接送社区区域、票价、行程开始月份、行程开始小时、行程开始日期、行程开始日期、行程开始时间、接送纬度、接送经度、下车纬度、下车经度、行程英里、上车人口普查地图、下车人口普查路线、付款类型、公司、行程时间、小费、下车区域 60,27.05,10,2,3,1380593700,41.836150155,-87.648787952,12.6,Cash,Taxi Affiliation Services,1380,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,1380593700]}'

回复: {"error": "预测失败:错误处理输入:预期的字符串,而是得到 27.05 类型的 'float'。"}

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

对于一些评论:如果我将单个 qoutes 添加到 double 并更新空值以使其为零:

请求正文:

{"instances":["Taxi Affiliation Services","'0'","'27.05'","'60,41.836150155'","'-87.648787952'","'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>"

}

解决方法

请尝试以下格式:-

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

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...