[英]Error in Call to Sagemaker Endpoint with Lambda and API Gateway
我尝试在 Sagemaker 中使用 TensorFlow-Keras model 进行预测,但收到以下错误:
在 Amazon Cloudwatch 中,对于 Lambda Function:
An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (415) from model with message "
{
"error": "Unsupported Media Type: application/x-image"
}
在 Cloudwatch 中,对于 Sagemaker:
F external/org_tensorflow/tensorflow/core/util/tensor_format.h:426] Check failed: index >= 0 && index < num_total_dims Invalid index from the dimension: 3, 0, C
Data is an image send in base64, the Lambda function convert this img to bytes, Lambda Function is:
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
data = json.loads(json.dumps(event))
payload = data['foto']
image = base64.b64decode(payload)
print(type(image))
try:
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType='application/x-image',
Body=image)
print(response)
except Exception as e:
print("error en inferencia:")
print(e)
return payload # only for test
您似乎正在使用 SageMaker v2。 使用 v2,您无需直接设置content_type
,而是在Serializer
实例中设置内容类型。 您可以在 Predictor 的构造函数中执行此操作,也可以在之后设置predictor.serializer
。 请注意,您可以使用已经创建的序列化程序 class ,它允许您指定content_type
或实现 class ,您可以在其中自定义它以处理content_type
。
我认为不支持content_type='application/x-image'
SageMaker TensorFlow 服务容器支持以下请求内容类型:
SageMaker TensorFlow 服务容器支持以下请求内容类型:
以及以下用于响应的内容类型:
您可以查看此答案Amazon SageMaker Unsupported content-type application/x-image ,其中几乎没有建议。
您需要创建自己的自定义 docker 以将 model 部署为服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.