簡體   English   中英

AWS SageMaker:使用托管在 S3 中的經過訓練的 model 創建終端節點

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

我有這個教程,主要針對jupyter notebook,對外部處理做了一些小的修改。 我創建了一個項目,可以在本地准備我的數據集,將其上傳到 S3,訓練,最后將 model 預測器部署到同一個存儲桶。 完美的!

因此,經過訓練並將其保存在 S3 存儲桶中:

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

部署為端點時失敗。 因此,我發現了以多種方式托管端點的技巧,但不是來自已保存在 S3 中的 model。 因為為了托管,您可能需要獲取估算器,通常情況下是這樣的:

 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)

我的問題是:有沒有辦法從保存在 S3 (.tar) 中的 model 加載估計器? 或者,無論如何,創建一個端點而不再次訓練它?

所以,在跑了很多頁之后,才在這里找到了線索。 我終於找到了如何加載 model 並創建端點:

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

請不要忘記在使用后禁用您的端點。 這真的很重要! 端點通過“運行”來收費,而不僅僅是使用

我希望它也可以幫助你!

  1. 使用以下代碼部署 model

     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. 初始化預測器

    model_predictor = sagemaker.Predictor( endpoint_name= model.endpoint_name, )
  3. 最后預測使用

    model_predictor.predict(##your payload)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM