K.Pil
K.Pil

Reputation: 986

Tensorflow GCP online Endpoint prediction instance Key and values format

Running a time series analysis on Iowa liquor sales data. I am able to train the model using TensorFlow and deployed it to an endpoint

As per the GCP docs, I am referring to this code sample to invoke an API endpoint for prediction:

https://github.com/googleapis/python-aiplatform/blob/master/samples/snippets/predict_custom_trained_model_sample.py

I am running into an issue where no matter how I enter instance values I am running into formatting errors.

currently the way I am calling the method is :

 predict_custom_trained_model_sample(
    project="XXXX",
    endpoint_id="YYY",
    location="us-central1",
    instance_dict={ "instances":[
                                    {
                                    "date" : '03-10-2021',
                                    "store_name" : "CENTRAL CITY LIQUOR, INC.",
                                    "category_name" : "IMPORTED DISTILLED SPIRIT SPECIALTY",
                                    "vendor_name" : "JINRO AMERICA INC",
                                    "item_description" : "JINRO CHAMISUL FRESH SOJU"
                                    }
                                ]})

The error I am getting :

InvalidArgument: 400 Failed to handle request. endpoint_id: xxxxx, deployed_model_id: xxxxx with error: `{
    "error": "Failed to process element: 0 key: instances of 'instances' list. Error: Invalid argument: JSON object: does not have named input: instances"
}`

I am trying to run the prediction on a single item value. Can someone point to the right syntax or if there are any other deeper issues to my problem?

Upvotes: 1

Views: 431

Answers (2)

Ricky Nguyen
Ricky Nguyen

Reputation: 41

Can you try this instead? From looking at the code, looks like it only accepts one instance that needs to be a Dict:

 predict_custom_trained_model_sample(
    project="XXXX",
    endpoint_id="YYY",
    location="us-central1",
    instance_dict={
        "date" : '03-10-2021',
        "store_name" : "CENTRAL CITY LIQUOR, INC.",
        "category_name" : "IMPORTED DISTILLED SPIRIT SPECIALTY",
        "vendor_name" : "JINRO AMERICA INC",
        "item_description" : "JINRO CHAMISUL FRESH SOJU"
    })

Upvotes: 0

guillaume blaquiere
guillaume blaquiere

Reputation: 75820

From the example, I understand that the instance_dict contain only the array of instance and not the instances key

 predict_custom_trained_model_sample(
    project="XXXX",
    endpoint_id="YYY",
    location="us-central1",
    instance_dict=[
      {
        "date" : '03-10-2021',
        "store_name" : "CENTRAL CITY LIQUOR, INC.",
        "category_name" : "IMPORTED DISTILLED SPIRIT SPECIALTY",
        "vendor_name" : "JINRO AMERICA INC",
        "item_description" : "JINRO CHAMISUL FRESH SOJU"
      }
    ])

Upvotes: 1

Related Questions