簡體   English   中英

如何在 amazon sagemaker 中加載訓練有素的 model?

[英]How to load trained model in amazon sagemaker?

我正在關注如何在 Amazon-sagemaker 中訓練機器學習 model 的示例

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)

那么在調用fit function 之后model 應該保存在S3 存儲桶中嗎? 下次如何加載這個 model?

這可以通過使用結合推理 Model的 sagemaker 庫來完成。

model = sagemaker.model.Model(
    image=image
    model_data='s3://bucket/model.tar.gz',
    role=role_arn)

您傳入的選項是:

  • image - 這是您用於推理的 ECR 圖像(應該用於您嘗試使用的算法)。 路徑可在此處獲得。
  • model_data - 這是您的 model 的存儲路徑(在tar.gz壓縮存檔中)。
  • role - 這是一個既能從 ECR 拉取圖像又能獲取 s3 存檔的角色的 arn。

成功完成此操作后,您將需要設置一個端點,這可以通過部署 function在您的筆記本中執行以下操作來完成。

model.deploy(
   initial_instance_count=1,
   instance_type='ml.p2.xlarge'
)

暫無
暫無

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

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