简体   繁体   中英

How to load trained model in amazon sagemaker?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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