如何在 amazon sagemaker 中加载经过训练的模型?
How to load trained model in amazon sagemaker?
我正在关注 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)
所以在调用拟合函数后,模型应该保存在 S3 存储桶中??下次怎么加载这个模型?
这可以通过结合使用 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'
)
我正在关注 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)
所以在调用拟合函数后,模型应该保存在 S3 存储桶中??下次怎么加载这个模型?
这可以通过结合使用 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'
)