简体   繁体   English

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

[英]Loading trained model in to SageMaker Estimator

I've trained a custom model on sagemaker based on PyTorch estimator.我已经基于 PyTorch 估计器在 sagemaker 上训练了一个自定义模型。
Training has been completed, and I verified that the model artifacts have been saved into s3 location.训练已完成,我验证了模型工件已保存到 s3 位置。

I want to load my trained model into my sagemaker notebooks so I can perform analysis/inference so on ...我想将我训练好的模型加载到我的 sagemaker 笔记本中,以便我可以执行分析/推理等等......

I did as below but I am not sure if this is the right method to do this as it asks for instance type, and to my knowledge, If I were to load the already trained estimator, I would need to declare which type of computing instance I use once I start deploying the model for inference.我做了如下,但我不确定这是否是正确的方法,因为它要求实例类型,据我所知,如果我要加载已经训练好的估计器,我需要声明哪种类型的计算实例一旦我开始部署模型进行推理,我就会使用它。

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

If training has been completed and you want to setup for inference then you want to point to your tar.gz model artifact file to create an endpoint or take your training estimator directly.如果训练已经完成并且您想要设置推理,那么您想要指向您的 tar.gz 模型工件文件以创建端点或直接使用您的训练估计器。 The following code block is the general flow that you want to follow for training, inference, and predictions.以下代码块是您要遵循的用于训练、推理和预测的一般流程。

# 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)

For more information check out the following link for deploying PyTorch models on SageMaker.有关更多信息,请查看以下链接以在 SageMaker 上部署 PyTorch 模型。 https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#deploy-pytorch-models https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#deploy-pytorch-models

I work for AWS & my opinions are my own我为 AWS 工作,我的意见是我自己的

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

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