【问题标题】:ValueError while deploying tensorflow model to Amazon SageMaker将 tensorflow 模型部署到 Amazon SageMaker 时出现 ValueError
【发布时间】:2019-08-07 23:45:12
【问题描述】:

我想将训练有素的 tensorflow 模型部署到 amazon sagemaker,我正在按照此处的官方指南:https://aws.amazon.com/blogs/machine-learning/deploy-trained-keras-or-tensorflow-models-using-amazon-sagemaker/ 使用 jupyter notebook 部署我的模型。

但是当我尝试使用代码时:

predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type='ml.t2.medium')

它给了我以下错误信息:

ValueError:托管端点 sagemaker-tensorflow-2019-08-07-22-57-59-547 时出错:失败原因:图像 '520713654638.dkr.ecr.us-west-1.amazonaws.com/sagemaker- tensorflow:1.12-cpu-py3 '不存在。

我认为教程没有告诉我创建图像,我不知道该怎么做。

import boto3, re
from sagemaker import get_execution_role

role = get_execution_role()

# make a tar ball of the model data files
import tarfile
with tarfile.open('model.tar.gz', mode='w:gz') as archive:
    archive.add('export', recursive=True)

# create a new s3 bucket and upload the tarball to it
import sagemaker

sagemaker_session = sagemaker.Session()
inputs = sagemaker_session.upload_data(path='model.tar.gz', key_prefix='model')

from sagemaker.tensorflow.model import TensorFlowModel
sagemaker_model = TensorFlowModel(model_data = 's3://' + sagemaker_session.default_bucket() + '/model/model.tar.gz',
                                  role = role,
                                  framework_version = '1.12',
                                  entry_point = 'train.py',
                                  py_version='py3')

%%time
#here I fail to deploy the model and get the error message
predictor = sagemaker_model.deploy(initial_instance_count=1,
                                   instance_type='ml.m4.xlarge')

【问题讨论】:

  • 对于未来的读者,在我的情况下,我不得不提到 py_version='py2' 才能让它工作。

标签: python amazon-web-services tensorflow amazon-s3 amazon-sagemaker


【解决方案1】:

https://github.com/aws/sagemaker-python-sdk/issues/912#issuecomment-510226311

如问题中所述

使用 TensorFlowModel 对象不支持 Python 3,因为容器使用 TensorFlow 服务 api 库和 GRPC 客户端来处理推理,但是 Python 3 正式不支持 TensorFlow 服务 api,所以有使用 TensorFlowModel 对象时,它们只是容器的 Python 2 版本。

如果您需要 Python 3,则需要使用上面 #2 中定义的模型对象。如果您需要处理预处理和后处理,推理脚本格式将发生变化。 https://github.com/aws/sagemaker-tensorflow-serving-container#prepost-processing.

【讨论】:

  • 非常感谢!删除py_version='py3' 后,现在可以开始部署,但随后出现此错误:UnexpectedStatusException: Error hosting endpoint sagemaker-tensorflow-2019-08-09-16-29-57-306: Failed. Reason: The primary container for production variant AllTraffic did not pass the ping health check. Please check CloudWatch logs for this endpoint.
  • 这是朝着正确方向迈出的一步,但正如错误所说,我会尝试检查 CloudWatch 中的日志。如果您无法辨别发生了什么,请将日志粘贴到此处,也许我们可以提供帮助。或者尝试联系支持...
猜你喜欢
  • 1970-01-01
  • 2021-03-26
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-05
  • 1970-01-01
相关资源
最近更新 更多