0

I trained a custom yolov5 model and deployed it to a sagemaker endpoint bby referring this blog : https://aws.amazon.com/blogs/machine-learning/scale-yolov5-inference-with-amazon-sagemaker-endpoints-and-aws-lambda/

Model Deployment :

model = TensorFlowModel(model_data=model_data,
                        framework_version='2.8', role=role)

predictor = model.deploy(initial_instance_count=1,
                            instance_type=INSTANCE_TYPE,
                            endpoint_name=ENDPOINT_NAME)

Here's how I am trying to pass the image for inference to the sagemaker endpoint :

s3 = boto3.client('s3')
response = s3.get_object(Bucket=bucket_name, Key=key)
image_data = response['Body'].read()

# Resize the image to 640x640 using Pillow
image = Image.open(io.BytesIO(image_data))
image = image.resize((640, 640))

# Convert the resized image to a NumPy array
image_array = np.array(image)

# 
image_data = np.array(image_array.astype(np.float32)/255.)
image_payload = json.dumps([image_data.tolist()])
import boto3
from botocore.config import Config

ENDPOINT_NAME = 'yolov5-inference-test-new'

client = boto3.client('sagemaker-runtime', region_name = 'ap-southeast-2')

response = client.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='application/json',
Body=image_payload)

But it throws a SSL validation failed error. I checked my region and the region of my notebook, boto3 client and sagemaker endpoint are all the same.

Interestingly, when I tried to pass a blank image to the endpoint ,it worked fine without any errors.

blank_image = np.zeros((modelHeight,modelWidth,3), np.uint8)

blank_data = np.array(blank_image.astype(np.float32)/255.)
blank_payload = json.dumps([blank_data.tolist()])

Please help me fix this.

Error

After referring some fixes , I checked my region and the region of my notebook, boto3 client and sagemaker endpoint are all the same, still the error persists.

  • Where are you trying to make the invoke_endpoint call from? Have you tried a different laptop/notebook instance/networking set up? – Marc Karp May 18 '23 at 16:00
  • I am trying to call the endpoint from the same notebook I used to deploy the endpoint. – InvisibleEcho May 20 '23 at 17:04
  • I suggest confirming if you can invoke the endpoint from a different notebook (different network config) or from your local laptop using the SDK or boto3 – Marc Karp May 22 '23 at 03:34

1 Answers1

0

Try invoking using other ContentType like application/x-npy, most likely the error caused by too big of payload as reference of S3 SDK. https://github.com/aws/aws-cli/discussions/7735