我通过参考此博客训练了一个自定义 yolov5 模型并将其部署到 sagemaker 端点:https://aws.amazon.com/blogs/machine-learning/scale-yolov5-inference-with-amazon-sagemaker-endpoints-和-aws-lambda/
模型部署:
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)
以下是我尝试将图像传递到 sagemaker 端点进行推理的方法:
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)
但它会抛出 SSL 验证失败错误。我检查了我的区域和笔记本、boto3 客户端和 sagemaker 端点的区域都是相同的。
有趣的是,当我尝试将空白图像传递到端点时,它工作正常,没有任何错误。
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()])
请帮我解决这个问题。
参考一些修复后,我检查了我的区域和我的笔记本、boto3 客户端和 sagemaker 端点的区域都是相同的,但错误仍然存在。
尝试使用
application/x-npy
等其他ContentType调用,很可能是由于S3 SDK的参考负载太大而导致的错误。 https://github.com/aws/aws-cli/discussions/7735
你修好了吗?我面临同样的问题 [ERROR] SSLError: SSL 验证失败 https://runtime.sagemaker.eu-north-1.amazonaws.com/endpoints/yolov5l-demo/invices EOF 发生违反协议 (_ssl .c:2406)