Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error from Vertex AI Getting predictions from custom trained models

I am trying to call an API to inference from a model I have uploaded to vertex AI.

I have tried three methods, and none worked so far.

At first, I was following a youtube from standford university, https://www.youtube.com/watch?v=fw6NMQrYc6w&t=3876s which uses ai platform.

1. I also tried that, but I think google is trying to get rid of AI platform, and although I succesfully uploaded the model, it doesn't allow me to make a new version, basically allows me nothing.

2. I tried to work this tutorial, https://codelabs.developers.google.com/vertex-p2p-predictions#5 

and it keeps complaining that my payload is above 1.5MB limit, but my image is only 49KB, so it's ridiculous. maybe something happened in this code, but it's from the tutorial, so the tutorial must be wrong then.

 

IMAGE_PATH = "test-image.jpg"
im = Image.open(IMAGE_PATH)
x_test = np.asarray(im).astype(np.float32).tolist()
endpoint.predict(instances=x_test).predictions

 

3. Last, I've been trying to call the API from the sample code,

https://github.com/googleapis/python-aiplatform/blob/main/samples/snippets/prediction_service/predic...

but it gives me a json format error.

I have referenced from this website to get the json format.

https://github.com/googleapis/python-aiplatform/blob/main/samples/snippets/prediction_service/predic... 

The error I am getting is as is : 

400 { "error": "Failed to process element: 0 key: instances of 'instances' list. Error: Invalid argument: JSON object: does not have named input: instances" }
 
The code that I have used is :
 

 

    encoded_content = base64.b64encode(image).decode("utf-8")
    instances = {"instances": {"image": {"b64": encoded_content}}, "key": "0"}

 

and the 400 error comes from API and the log from vertex AI is not very useful when debugging.

Honestly I have been struggling with this issue for days and in my opinion, this should not be this difficult. My experience with GCP and vertex AI is very disappointing and I'm considering to explore other options. Please let me know if any of you have any advices. Thanks

Solved Solved
0 3 12.4K
1 ACCEPTED SOLUTION

3 REPLIES 3