我尝试在 Sagemaker 中使用 TensorFlow-Keras 模型进行预测,但收到以下错误:
在 Amazon Cloudwatch 中,对于 Lambda 函数:
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
数据是以base64发送的图像,Lambda函数将此图像转换为字节,Lambda函数是:
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
来执行此操作。请注意,您可以使用已创建的序列化程序类,该类允许您指定 content_type
,或者实现一个自定义类来处理 content_type
。
关于amazon-web-services - 使用 Lambda 和 API 网关调用 Sagemaker 端点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66316372/