繁体   English   中英

将经过训练的模型加载到 SageMaker Estimator

[英]Loading trained model in to SageMaker Estimator

我已经基于 PyTorch 估计器在 sagemaker 上训练了一个自定义模型。
训练已完成,我验证了模型工件已保存到 s3 位置。

我想将我训练好的模型加载到我的 sagemaker 笔记本中,以便我可以执行分析/推理等等......

我做了如下,但我不确定这是否是正确的方法,因为它要求实例类型,据我所知,如果我要加载已经训练好的估计器,我需要声明哪种类型的计算实例一旦我开始部署模型进行推理,我就会使用它。

estimator = PyTorch(
        model_data = ModelArtifact_S3_LOCATION,
        entry_point ='train.py',
        source_dir = 'code',
        role = role,
        framework_version = '1.5.0',
        py_version = 'py3',)

如果训练已经完成并且您想要设置推理,那么您想要指向您的 tar.gz 模型工件文件以创建端点或直接使用您的训练估计器。 以下代码块是您要遵循的用于训练、推理和预测的一般流程。

# Train my estimator
pytorch_estimator = PyTorch(entry_point='train_and_deploy.py',
                            instance_type='ml.p3.2xlarge',
                            instance_count=1,
                            framework_version='1.8.0',
                            py_version='py3')
pytorch_estimator.fit('s3://my_bucket/my_training_data/')

# Deploy my estimator to a SageMaker Endpoint and get a Predictor
predictor = pytorch_estimator.deploy(instance_type='ml.m4.xlarge',
                                     initial_instance_count=1)

# `data` is a NumPy array or a Python list.
# `response` is a NumPy array.
response = predictor.predict(data)

有关更多信息,请查看以下链接以在 SageMaker 上部署 PyTorch 模型。 https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#deploy-pytorch-models

我为 AWS 工作,我的意见是我自己的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM