Amazon web services 如何在amazon sagemaker中加载经过训练的模型?

Amazon web services 如何在amazon sagemaker中加载经过训练的模型?,amazon-web-services,amazon-s3,amazon-sagemaker,Amazon Web Services,Amazon S3,Amazon Sagemaker,我正在关注如何在Amazon sagemaker中训练机器学习模型 data_location = 's3://{}/kmeans_highlevel_example/data'.format(bucket) output_location = 's3://{}/kmeans_highlevel_example/output'.format(bucket) print('training data will be uploaded to: {}'.format(data_location))

我正在关注如何在Amazon sagemaker中训练机器学习模型

data_location = 's3://{}/kmeans_highlevel_example/data'.format(bucket)
output_location = 's3://{}/kmeans_highlevel_example/output'.format(bucket)

print('training data will be uploaded to: {}'.format(data_location))
print('training artifacts will be uploaded to: {}'.format(output_location))

kmeans = KMeans(role=role,
                train_instance_count=2,
                train_instance_type='ml.c4.8xlarge',
                output_path=output_location,
                k=10,
                epochs=100,
                data_location=data_location)

因此,调用fit函数后,模型应保存在S3存储桶中??下次如何加载此模型?

这可以通过使用sagemaker库和

您要传递的选项有:

  • image
    -这是您用于推断的ECR图像(应适用于您尝试使用的算法)。路径可用
  • model\u data
    -这是存储模型的路径(在
    tar.gz
    压缩存档中)
  • 角色
    -这是一个角色的arn,它能够从ECR中提取映像并获取s3存档
成功完成此操作后,您将需要设置端点,可以通过在笔记本中通过执行以下操作来完成此操作


还有一个问题。在训练模型时,我没有指定任何关于ECR映像的内容,事实上,我甚至没有ECR存储库。这是否意味着我必须再次训练模型,以便从S3部署它。如果您使用
Kmeans
模型,它将自动为您选择此模型:)
model = sagemaker.model.Model(
    image=image
    model_data='s3://bucket/model.tar.gz',
    role=role_arn)
model.deploy(
   initial_instance_count=1,
   instance_type='ml.p2.xlarge'
)