首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何部署之前使用Amazon Sagemaker训练并存储在S3存储桶中的现有pytorch模型

如何部署之前使用Amazon Sagemaker训练并存储在S3存储桶中的现有pytorch模型
EN

Stack Overflow用户
提问于 2020-03-04 23:08:02
回答 1查看 299关注 0票数 0

我已经使用SageMaker训练了一个Pytorch模型,该模型现在存储在一个S3存储桶中。我正在尝试检索该模型并部署它。

这是我使用的代码:

代码语言:javascript
复制
estimator = sagemaker.model.FrameworkModel(
    model_data= #link to  model location in s3
    image=  # image
    role=role,
    entry_point='train.py', 
    source_dir='pytorch_source',
    sagemaker_session = sagemaker_session
) 

predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")

但在部署过程之后(似乎运行得很顺利),predictor只是一个NoneType。我在日志里没有发现任何奇怪的信息...

我还用下面的代码做了另一次尝试:

代码语言:javascript
复制
estimator = PyTorchModel(model_data= #link to model location in s3 
                             role=role,
                             image= #image
                             entry_point='pytorch_source/train.py',
                            predictor_cls = 'pytorch_source/train.py',
                           framework_version = '1.1.0')

predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")

但它甚至不能完成部署。

有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-06 21:00:35

我实际上使用PyTorchModel解决了这个问题,设置如下:

代码语言:javascript
复制
estimator = PyTorchModel(model_data='#path to model, 
                             role=role,
                             source_dir='pytorch_source',
                             entry_point='deploy.py',
                            predictor_cls = ImgPredictor,
                           framework_version = '1.1.0')

ImgPredictor在哪里

代码语言:javascript
复制
from sagemaker.predictor import RealTimePredictor, json_deserializer

class ImgPredictor(RealTimePredictor):
    def __init__(self, endpoint_name, sagemaker_session):
        super(ImgPredictor, self).__init__(endpoint_name, sagemaker_session, content_type='application/x-image', 
                                           deserializer = json_deserializer ,accept='application/json')

deploy.py包含所需的函数input_fn、output_fn、model_fn和predict_fn。此外,源目录中缺少requirements.txt文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60529048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档