3

I have an image that I upload to s3 in mybucket. Suppose my s3 endpoint for this data is s3://mybucket/imgname

Now I also have a model deployed in SageMaker at sagemaker-model-endpoint

I looked into examples of how to invoke this SageMaker endpoint from a boto client here but I am not sure how to specify the s3 path s3://mybucket/imgname in the invoke_endpoint call.

client = boto3.client("runtime.sagemaker", region_name = 's3.us-east-2.amazonaws.com') client.invoke_endpoint( EndpointName=sagemaker-model-endpoint Body=payload, ContentType='image/jpg', Accept='Accept') 

What should be the payload in this case? Where do I specify the s3 url?

2
  • 1
    I see it's been a couple years since you posted this... what did you end up doing? I'm in the exact same situation and the answers provided below are not what I want to do... I don't want to pass the actual image data to the SageMaker Endpoint. I just want to give it the S3 URI, and have it return the prediction. Commented Jul 21, 2021 at 0:36
  • 2
    @HovanesGasparian you basically need to change your inference code so it can read the image from S3 URI. After that, the remaining logic should be the same. Commented Jul 21, 2021 at 4:26

2 Answers 2

2

You need to have the bytes of the image, and after you get the image from S3 (S3 copy or wget), you can call:

with open(file_name, 'rb') as f: payload = f.read() payload = bytearray(payload) client.invoke_endpoint(EndpointName=sagemaker-model-endpoint, ContentType='application/x-image', Body=payload) 
Sign up to request clarification or add additional context in comments.

Comments

1

Guy's solution is for the case that you want your client download the image then client sends the image bytes to your model.

If you want to let your model do the image downloading, then you need to rework your model so that it can consume the s3 url either in the request body or via CustomAttributes header.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.