[英]Error in Call to Sagemaker Endpoint with Lambda and API Gateway
I try make predictions with a TensorFlow-Keras model in Sagemaker, but recive the next errors:我尝试在 Sagemaker 中使用 TensorFlow-Keras model 进行预测,但收到以下错误:
In Amazon Cloudwatch, for Lambda Function:在 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"
}
In Cloudwatch, for Sagemaker:在 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: 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
It seems that you are using SageMaker v2.您似乎正在使用 SageMaker v2。 With v2 you don't directly set
content_type
instead you set the content type in a Serializer
instance.使用 v2,您无需直接设置
content_type
,而是在Serializer
实例中设置内容类型。 You can either do this in the Predictor's constructor or by setting predictor.serializer
afterwards.您可以在 Predictor 的构造函数中执行此操作,也可以在之后设置
predictor.serializer
。 Note that you can use an already created serializer class that allows you to specify a content_type
or alternatively implement a class where you customize it to handle content_type
.请注意,您可以使用已经创建的序列化程序 class ,它允许您指定
content_type
或实现 class ,您可以在其中自定义它以处理content_type
。
I think content_type='application/x-image'
is not supported我认为不支持
content_type='application/x-image'
how to handle application/x-image? 如何处理应用程序/x-image?
SageMaker TensorFlow Serving Container supports the following Content-Types for requests: SageMaker TensorFlow 服务容器支持以下请求内容类型:
SageMaker TensorFlow Serving Container supports the following Content-Types for requests: SageMaker TensorFlow 服务容器支持以下请求内容类型:
And the following content types for responses:以及以下用于响应的内容类型:
you can check this answer Amazon SageMaker Unsupported content-type application/x-image which has few suggestions.您可以查看此答案Amazon SageMaker Unsupported content-type application/x-image ,其中几乎没有建议。
You need create your own custom docker to deploy the model as a service.
您需要创建自己的自定义 docker 以将 model 部署为服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.