这是我第一次使用亚马逊网络服务来部署我的机器学习预训练模型。我想将预训练的 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.).
我不知道我错在哪里,我已经浪费了两天时间来解决这个错误,但找不到有关此问题的信息。我分享过的详细日志here 。
我的笔记本实例的 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 中的服务。它们具有不同的类表示形式和文档,如此处所示。
- TensorFlowModel - https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/model.py#L47
- 文档: https://github.com/aws/sagemaker-python-sdk/tree/v1.12.0/src/sagemaker/tensorflow#deploying-directly-from-model-artifacts
- 主要区别:使用代理 GRPC 客户端发送请求
- 容器实现: https://github.com/aws/sagemaker-tensorflow-container/blob/master/src/tf_container/serve.py
- 型号 - https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/serving.py#L96
- 文档:https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst
- 主要区别:利用 TensorFlow 服务 REST API
- 容器实现:https://github.com/aws/sagemaker-tensorflow-serving-container/blob/master/container/sagemaker/serve.py
Python 3 不支持使用 TensorFlowModel
对象,因为容器将 TensorFlow 服务 API 库与 GRPC 客户端结合使用来处理推理,但是 TensorFlow 服务 API 不支持Python 3 正式支持,因此使用 TensorFlowModel
对象时只有 Python 2 版本的容器。
如果您需要 Python 3,那么您将需要使用上面 #2 中定义的 Model
对象。
最后,我使用了 TensorFlow 版本 1.15.1 的模型
。
sagemaker_model = Model(model_data = model_data, role = role, framework_version='1.15.2', entry_point = 'train.py')
关于amazon-web-services - 在 aws sagemaker 上部署预训练的 tensorflow 模型 - ModelError : An error occurred (ModelError) when calling the InvokeEndpoint operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61074798/