Winthan Aung
Winthan Aung

Reputation: 351

Python Google Prediction example

predict_custom_model_sample(
    "projects/794xxx496/locations/us-central1/xxxx/3452xxx524447744",
    { "instance_key_1": "value", ... },
    { "parameter_key_1": "value", ... }
)

Google is giving this example, I am not understanding the parameter_key and instance_key. To my understanding, I need to send the JSON instance.

{"instances": [  {"when": {"price": "1212"}}]}

How can I make it work with the predict_custom_model_sample?

Upvotes: 0

Views: 146

Answers (1)

Ksign
Ksign

Reputation: 817

I assume that you are trying this codelab.
Note that there seems to be a mismatch between the function name defined (predict_tabular_model) and the function name used (predict_custom_model_sample).

INSTANCES is an array of one or more JSON values of any type. Each values represents an instance that you are providing a prediction for.
Instant_key_1 is just the first key of the key/value that goes into instances.

Similarly, parameter_key_1 is just the first key of the key/value that goes into the parameters JSON object.
If your model uses a custom container, your input must be formatted as JSON, and there is an additional parameters field that can be used for your container.

PARAMETERS is a JSON object containing any parameters that your container requires to help serve predictions on the instances. AI Platform considers the parameters field optional, so you can design your container to require it, only use it when provided, or ignore it.

Ref.: https://cloud.google.com/ai-platform-unified/docs/predictions/custom-container-requirements#request_requirements

Here you have examples of inputs for online predictions from custom-trained models

For the codelab, I believe you can use the sample provided:

test_instance={
    'Time': 80422,
    'Amount': 17.99,
…
}

And then call for prediction (Remember to check for the function name in the notebook cell above)

predict_custom_model_sample(
   "your-endpoint-str",
    test_instance
)

Upvotes: 1

Related Questions