【问题标题】:Deploy pre-trained tensorflow model on the aws sagemaker - ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation在 aws sagemaker 上部署预训练的 tensorflow 模型 - ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError)
【发布时间】:2020-04-07 07:26:24
【问题描述】:

这是我第一次使用亚马逊网络服务来部署我的机器学习预训练模型。我想将我预训练的 TensorFlow 模型部署到 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 天时间来解决这个错误,但找不到与此相关的信息。我分享的详细日志here

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

【问题讨论】:

    标签: amazon-web-services tensorflow tensorflow-serving amazon-sagemaker


    【解决方案1】:

    经过大量搜索和尝试错误,我能够解决这个问题。在许多情况下,问题是由 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 中的服务。它们有不同的类表示和文档,如下所示。

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

    不支持使用TensorFlowModel 对象的 Python 3,因为容器使用 TensorFlow 服务 API 库和 GRPC 客户端来处理推理,但是 Python 3 正式不支持 TensorFlow 服务 API ,因此在使用 TensorFlowModel 对象时只有 Python 2 版本的容器。 如果您需要 Python 3,则需要使用上面 #2 中定义的 Model 对象。

    最后,我在 TensorFlow 版本 1.15.1 中使用了 Model

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

    另外,这里是成功的结果。

    【讨论】:

      猜你喜欢
      • 2023-02-05
      • 2020-11-15
      • 2019-01-28
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-30
      相关资源
      最近更新 更多