在Amazon SageMaker中,不支持直接使用“application/x-image”作为内容类型。然而,您可以通过以下代码示例来解决这个问题:
import boto3
# 创建SageMaker客户端
client = boto3.client('sagemaker-runtime')
# 定义您的模型参数
endpoint_name = 'your-endpoint-name'
content_type = 'image/jpeg' # 指定正确的内容类型
# 读取图像文件
with open('your-image.jpg', 'rb') as f:
payload = f.read()
# 发起预测请求
response = client.invoke_endpoint(
EndpointName=endpoint_name,
ContentType=content_type,
Body=payload
)
# 处理预测结果
result = response['Body'].read()
print(result)
在上述代码中,您需要将your-endpoint-name替换为您SageMaker端点的名称,并将your-image.jpg替换为您要预测的图像文件。content_type变量应设置为正确的图像文件类型,例如image/jpeg。
注意,您可以根据需要更改代码中的其他参数和预处理步骤,以适应您的具体情况。
上一篇:Amazon Sagemaker - 无法评估提供的载荷
下一篇:Amazon SageMaker Ground Truth 自定义标注作业错误:无法读取空值的 'taskInput' 属性。