简体   繁体   中英

AWS SageMaker: Create an endpoint using a trained model hosted in S3

I have following this tutorial , which is mainly for jupyter notebook, and made some minimal modification for external processing. I've created a project that could prepare my dataset locally, upload it to S3, train, and finally deploy the model predictor to the same bucket. Perfect!

So, after to train and saved it in S3 bucket:

 ss_model.fit(inputs=data_channels, logs=True)

it failed while deploying as an endpoint. So, I have found tricks to host an endpoint in many ways, but not from a model already saved in S3. Because in order to host, you probably need to get the estimator, which in normal way is something like:

 self.estimator = sagemaker.estimator.Estimator(self.training_image,
                                                role,
                                                train_instance_count=1,
                                                train_instance_type='ml.p3.2xlarge',
                                                train_volume_size=50,
                                                train_max_run=360000,
                                                output_path=output,
                                                base_job_name='ss-training',
                                                sagemaker_session=sess)

My question is: is there a way to load an estimator from a model saved in S3 (.tar)? Or, anyway, to create an endpoint without train it again?

So, after to run on many pages, just found a clue here . And I finally found out how to load the model and create the endpoint:

def create_endpoint(self):
    sess = sagemaker.Session()
    training_image = get_image_uri(sess.boto_region_name, 'semantic-segmentation', repo_version="latest")        
    role = "YOUR_ROLE_ARN_WITH_SAGEMAKER_EXECUTION"
    model = "s3://BUCKET/PREFIX/.../output/model.tar.gz"

    sm_model = sagemaker.Model(model_data=model, image=training_image, role=role, sagemaker_session=sess)
    sm_model.deploy(initial_instance_count=1, instance_type='ml.p3.2xlarge')

Please, do not forget to disable your endpoint after using. This is really important! Endpoints are charged by "running" not only by the use

I hope it also can help you out!

  1. Deploy the model using the following code

     model = sagemaker.Model( role=role, model_data=### s3 location of tar.gz file, image_uri= ### the inference image uri, sagemaker_session =sagemaker_session, name =## model name) model_predictor = model.deploy(initial_instance_count=1, instance_type=instance_type, )
  2. Initialize the predictor

    model_predictor = sagemaker.Predictor( endpoint_name= model.endpoint_name, )
  3. Finally predict using

    model_predictor.predict(##your payload)

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