Reputation: 11
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.
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.
Upvotes: 1
Views: 1265
Reputation: 1
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
Upvotes: 0