簡體   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