【问题标题】:How to load trained model in amazon sagemaker?如何在 amazon sagemaker 中加载训练有素的模型?
【发布时间】:2020-07-19 12:36:37
【问题描述】:

我正在关注this example,了解如何在 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 存储桶中??下次怎么加载这个模型?

【问题讨论】:

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


    【解决方案1】:

    这可以通过结合使用 sagemaker 库和 Inference Model 来完成。

    model = sagemaker.model.Model(
        image=image
        model_data='s3://bucket/model.tar.gz',
        role=role_arn)
    

    你传入的选项是:

    • image - 这是您用于推理的 ECR 图像(应该用于您尝试使用的算法)。路径可用here
    • model_data - 这是存储模型的路径(在 tar.gz 压缩存档中)。
    • role - 这是一个既能从 ECR 拉取图像又能获取 s3 存档的角色。

    成功完成此操作后,您需要设置一个端点,这可以通过deploy function 在您的笔记本中执行以下操作来完成。

    model.deploy(
       initial_instance_count=1,
       instance_type='ml.p2.xlarge'
    )
    

    【讨论】:

    • 再问一个问题。当我训练模型时,我没有指定关于 ECR 图像的任何内容,事实上我什至没有 ECR 存储库。这是否意味着我必须再次训练模型才能从 S3 部署它。
    • 没有图像就无法训练,如果你使用Kmeans 模型,它会自动为你选择这个:)
    猜你喜欢
    • 2020-11-18
    • 1970-01-01
    • 2018-02-13
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 2020-06-29
    • 2020-02-08
    相关资源
    最近更新 更多