Amazon SageMaker不支持的内容类型应用程序/x图像 [英] Amazon SageMaker Unsupported content-type application/x-image

查看:98
本文介绍了Amazon SageMaker不支持的内容类型应用程序/x图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Sagemaker中部署了基于tensorflow/keras的CNN模型.

I have a tensorflow/keras based CNN model deployed in Sagemaker.

现在要调用推断,我遵循了这个教程

Now to invoke the inference, I followed this tutorial

下面的代码段

def inferImage(endpoint_name):
    # Load the image bytes
    img = open('./shoe.jpg', 'rb').read()
    runtime = boto3.Session().client(service_name='sagemaker-runtime')

    # Call your model for predicting which object appears in this image.
    response = runtime.invoke_endpoint(
        EndpointName=endpoint_name,
        ContentType='application/x-image',
        Body=bytearray(img))
    response_body = response['Body']
    print(response_body.read()) 

运行此代码时,出现错误

When I run this code, I get error

不支持的内容类型应用程序/x图像

我想念什么?关于如何修复它的任何建议?

What am I missing? Any suggestion on how to fix it?

推荐答案

您是否使用了SageMaker python sdk?如果是,则可以参考此自述文件 https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_python.rst 并提供您自己的input_fn()来处理应用程序/x图像数据.

Did you use SageMaker python sdk? If yes, you could refer to this README https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_python.rst and provide your own input_fn() to deal with application/x-image data.

如果您未在用户脚本中提供自定义的input_fn(),则默认的input_fn只能处理3种类型:"application/json","text/csv"和"application/octet-stream"

If you don't provide your customized input_fn() in the user script, the default input_fn can only handle 3 types: "application/json", "text/csv" and "application/octet-stream"

在此处引发异常: https://github.com/aws/sagemaker-tensorflow-container/blob/1e74bc6440cdd7e083d15026869e021c5ab504a4/src/tf_container/serve.py#L239

这篇关于Amazon SageMaker不支持的内容类型应用程序/x图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆