Reputation: 16365
I am following this example on how to train a machine learning model in 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)
So after calling the fit function the model should be saved in the S3 bucket?? How can you load this model next time?
Upvotes: 10
Views: 9479
Reputation: 35146
This can be done by using the sagemaker library combined with the Inference Model.
model = sagemaker.model.Model(
image=image
model_data='s3://bucket/model.tar.gz',
role=role_arn)
The options you're passing in are:
image
- This is the ECR image you're using for inference (which should be for the algorithm you're trying to use). Paths are available here.model_data
- This is the path of where your model is stored (in a tar.gz
compressed archive).role
- This is the arn of a role that is capable of both pulling the image from ECR and getting the s3 archive.Once you've successfully done this you will need to setup an endpoint, this can be done by performing the following in your notebook through the deploy function.
model.deploy(
initial_instance_count=1,
instance_type='ml.p2.xlarge'
)
Please note, the above is for a pre-trained model but will also work for BYOS (bring your own script). More information is available here.
Upvotes: 11