繁体   English   中英

在 aws sagemaker 上部署预训练的 tensorflow model - ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError)

[英]Deploy pre-trained tensorflow model on the aws sagemaker - ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation

这是我第一次使用亚马逊 web 服务来部署我的机器学习预训练 model。 我想将我预训练的 TensorFlow model 部署到 Aws-Sagemaker。 我能够以某种方式成功部署端点但是每当我调用predictor.predict(some_data)方法进行预测以调用端点时,它都会引发错误。

ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "". See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/sagemaker-tensorflow-2020-04-07-04-25-27-055 in account 453101909370 for more information.

通过云观察日志后,我发现了这个错误。

#011details = "NodeDef mentions attr 'explicit_paddings' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_BFLOAT16, DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]; attr=dilations:list(int),default=[1, 1, 1, 1]>; NodeDef: {{node conv1_conv/convolution}} = Conv2D[T=DT_FLOAT, _output_shapes=[[?,112,112,64]], data_format="NHWC", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](conv1_pad/Pad, conv1_conv/kernel/read). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).

我不知道我错在哪里,我已经浪费了 2 天时间来解决这个错误并且找不到关于这个的信息。 我在这里分享的详细日志。

Tensorflow 我的笔记本实例版本是1.15

经过大量的搜索和尝试和错误,我能够解决这个问题。 在许多情况下,由于 TensorFlow 和 Python 版本而出现问题。

问题的原因:为了部署端点,我在 TF 1.12 和 python 3 上使用了TensorflowModel ,这正是导致问题的原因。

 sagemaker_model = TensorFlowModel(model_data = model_data, role = role, framework_version = '1.12', entry_point = 'train.py')

显然, TensorFlowModel只允许在 TF 版本 1.11、1.12 上使用 python 2。 2.1.0。

我如何修复它:有两个 TensorFlow 解决方案可以处理 Python SDK 中的服务。 它们有不同的 class 表示和文档,如此处所示。

  1. TensorFlowModel - https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/model.py#L47
  1. Model - https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/serving.py#L96

Python 3 isn't supported using the TensorFlowModel object, as the container uses the TensorFlow serving API library in conjunction with the GRPC client to handle making inferences, however, the TensorFlow serving API isn't supported in Python 3 officially, so there are only Python 使用TensorFlowModel object 时的 2 个容器版本。 如果您需要 Python 3,那么您将需要使用上面 #2 中定义的Model object。

最后,我使用了Model和 TensorFlow 版本 1.15.1。

 sagemaker_model = Model(model_data = model_data, role = role, framework_version='1.15.2', entry_point = 'train.py')

此外,这里是成功的结果。 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM