bli00
bli00

Reputation: 2787

How to check the prediction format of AI Platform

I'm following the tutorial here but instead of saving the model local, I used vertex AI and to upload the the model to AI platform (following the tutorial here). When I try to run prediction I get the error message InvalidArgument: 400 { "error": "Failed to process element: 0 key: examples of 'instances' list. Error: Invalid argument: JSON Value: 10 Type: Number is not of expected type: string" }:

aiplatform.init(project=GOOGLE_CLOUD_PROJECT, location=GOOGLE_CLOUD_REGION)

# The AI Platform services require regional API endpoints.
client_options = {
    'api_endpoint': GOOGLE_CLOUD_REGION + '-aiplatform.googleapis.com'
    }
# Initialize client that will be used to create and send requests.
client = aiplatform.gapic.PredictionServiceClient(client_options=client_options)

features = {
  'culmen_length_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[49.9])),
  'culmen_depth_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[16.1])),
  'flipper_length_mm': tf.train.Feature(float_list=tf.train.FloatList(value=[213])),
  'body_mass_g': tf.train.Feature(float_list=tf.train.FloatList(value=[5400])),
}
example_proto = tf.train.Example(features=tf.train.Features(feature=features))
examples = example_proto.SerializeToString()

endpoint = client.endpoint_path(
    project=GOOGLE_CLOUD_PROJECT,
    location=GOOGLE_CLOUD_REGION,
    endpoint=ENDPOINT_ID,
)

# Send a prediction request and get response.
client.predict(endpoint=endpoint, instances=[{"examples": [examples]}])

I tried every many different combinations of the above but I'm still getting 400s. I'm looking at this post but the endpoint /metadata don't exist. I'm also looking at this documentation on how to format the json but it's not tell me much in relation to this example. How can I check the format of the prediction request for any particular API?

Upvotes: 0

Views: 403

Answers (0)

Related Questions