Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

tensorflow serving - How do I format the response body of a request to the predict endpoint of a Google Cloud Platform API request

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. The model from SchemaGen in Kubeflow
  2. The header from the data.csv I used for training and the row I extracted from it in which I want to test
  3. The curl Im using in postman and it's error.

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 from Kubeflow: enter image description here

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:

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]}'

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

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.

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

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'"]}

Respose:

{
"error": "Prediction failed: Error during model execution: <_MultiThreadedRendezvous of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Could not parse example input, value: 'Taxi Affiliation Services'
 [[{{node ParseExample/ParseExampleV2}}]]"
debug_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}"
>"

}

question from:https://stackoverflow.com/questions/65864518/how-do-i-format-the-response-body-of-a-request-to-the-predict-endpoint-of-a-goog

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please give a try with the below format :-

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...