Inference via sagemaker endpoint
Hi! How do i call this for inference with an image via a sagemaker endpoint?
send request
predictor.predict({
"inputs": "My name is Clara and I am", "parameters":parameters
})
This works, but how do i include an image in the input?
I tried this:
image_path ='./images/powercord.jpg'
with open(image_path, "rb") as f:
image = base64.b64encode(f.read()).decode("utf-8")
payload = { "inputs" :{
"prompt": "detect powercord",
"image": image
}}
query_response = predictor.predict(data=payload)
But im getting this error - An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (422) from primary with message "Failed to deserialize the JSON body into the target type: inputs: invalid type: map, expected a string at line 1 column 11".
Hi @shum123 ,
The model is expecting a JSON format where the inputs are passed in a way that it can deserialize into the expected structure. You're including both the prompt and the image in the inputs dictionary. You should pass the entire payload as a valid JSON string (json.dumps(payload)) in your request. Kindly use the below code.
payload = { "inputs": json.dumps({ "prompt": "detect powercord", "image": image }) }
Thank you.