简体   繁体   English

使用 Lambda 和 API 网关调用 Sagemaker 端点时出错

[英]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 服务容器支持以下请求内容类型:

  • application/json (default)应用程序/json(默认)
  • text/csv文本/csv
  • application/jsonlines应用程序/jsonlines

And the following content types for responses:以及以下用于响应的内容类型:

  • application/json (default)应用程序/json(默认)
  • application/jsonlines应用程序/jsonlines

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.

相关问题 我如何使用 API 网关调用 sagemaker 推理端点 - How can i call sagemaker inference endpoint using API gateway 如何使用Lambda和API网关部署由AWS Sagemaker创建的乳腺癌预测终端节点? - How to deploy breast cancer prediction endpoint created by AWS Sagemaker using Lambda and API gateway? 从 AWS Lambda function 调用授权的 Api 网关端点 - Call Authorized Api Gateway endpoint from AWS Lambda function AWS Lambda和API Gateway Endpoint响应中的调试错误 - Debugging error in AWS Lambda and API Gateway Endpoint response 从 Lambda 调用 API 网关 - Call API Gateway from Lambda 我应该在我的 api 网关资源策略中使用什么 cidr 范围来允许 lambda 调用我的端点? - What cidr range should I use in my api gateway resource policy to allow lambda to call my endpoint? 从 Lambda 调用外部 api 端点时出现 ENOTFOUND 错误 - ENOTFOUND error when call external api endpoint from Lambda aws api 网关和 lambda:多个端点/功能与单个端点 - aws api gateway & lambda: multiple endpoint/functions vs single endpoint 如何在C#中调用Sagemaker培训模型端点API - How to call Sagemaker training model endpoint API in C# 在 lambda 函数中调用 Sagemaker 端点 invoke_endpoint,请求正文格式的问题 - Call Sagemaker endpoint invoke_endpoint in lambda function, question for request body formats
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM