如何将请求的响应主体格式化为Google Cloud Platform API请求的预测端点 [英] How do I format the response body of a request to the predict endpoint of a Google Cloud Platform API request

查看:70
本文介绍了如何将请求的响应主体格式化为Google Cloud Platform API请求的预测端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理使用AI平台组件时在GCP上预先制作的教程.简而言之,它涉及使用Kubeflow和Tensorflow Extended来构建和部署完整的ML模型,以预测谁将成为Chicago Taxi数据集的重要牺牲品.甚至在部署和达到模型的预测端点之前,一切都进行得很好,但是,我似乎无法正确地获取请求主体,也找不到关于如何知道请求主体外观的良好文档.下面我有:

I'm working off of the tutorial that is premade on GCP when working with the AI Platform component. In short it involves using Kubeflow and Tensorflow Extended to build and deploy a completed ML model for predicting who will be a big tipper off of the Chicago Taxi dataset. Everything has gone well even up to deploying and hitting the predict endpoint of my model however, I can't seem to get the request body correct or find good documentation on how to know what the request body should look. Below I have:

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

值得注意的是,该错误讨论了预期的浮点数并获取了一个字符串,但是模型表示它应该是浮点数.我想知道是否有人可以帮助我确定数据类型,requestBody的顺序,以便获得成功的预测.预先感谢!

Of note, The error talks about expected a float and getting a string but the model says it should be a float. I'd like to know if anyone can help me determine the datatypes,ordering of the requestBody so I can get a successful prediction back. Thanks in advance!

SchemaGen:

SchemaGen from Kubeflow:

csv标头和数据行的副本:Pickup_community_area,票价,trip_start_month,trip_start_hour,trip_start_day,trip_start_timestamp,pickup_latitude,pickup_longitude,drop-off_latitude,dropoff_longitude,trip_miles,pickup_census_tract,dropoff_census_tract,付款类型,公司,trip,tipsipper60,27.05,10,2,3,1380593700,41.836150155,-87.648787952 ,,, 12.6 ,,现金,出租车分会会员服务,1380,,0,0

copy of csv header and data row: 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,,,Cash,Taxi Affiliation Services,1380,,0,0

卷曲:

curl --location --request POST'https://ml.googleapis.com/v1/projects/<<项目名称-此处/models/tfxmodel:predict'
--header'Authorization:Bearer<< TOKEN HERE'
--header'接受:application/json'
--header'Content-Type:application/json'
--data-raw'{"instances":["Taxi Affiliation Services",",,",,","27.05",现金",",60,41.836150155,-87.648787952,0,12.6,1380,3,2,10,1380593700]}'

curl --location --request POST 'https://ml.googleapis.com/v1/projects/<<project-name-here/models/tfxmodel:predict'
--header 'Authorization: Bearer <<TOKEN HERE'
--header 'Accept: application/json'
--header 'Content-Type: application/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'."}

Response: {"error": "Prediction failed: Error processing input: Expected string, got 27.05 of type 'float' instead."}

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

Of note if I start converting all the floats and ints to strings it ends up giving me an invalid requestbody error which doesn't suprise me.

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

To some of the comments: If I add single qoutes into double and also update the empty values to have a zero:

RequestBody:

RequestBody:

{"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",现金" \"60,41.836150155,-87.648787952,0,12.6,1380,3,2,10,1380593700"]}

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

您可以检查此链接中的CSV数据,并将每一行编码为字符串值:-

You can check this link for CSV data with each row encoded as a string value:- https://cloud.google.com/ai-platform/prediction/docs/reference/rest/v1/projects/predict#request-body-details

这篇关于如何将请求的响应主体格式化为Google Cloud Platform API请求的预测端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆