我已经使用 sagemaker 训练了一个语义分割模型,并且输出已保存到 s3 存储桶中。我想从 s3 加载这个模型来预测 sagemaker 中的一些图像。
我知道如何预测我是否让笔记本实例在训练后继续运行,因为它只是一个简单的部署,但如果我想使用旧模型并没有真正的帮助。
我已经查看了这些来源,并且能够自己想出一些东西,但它不起作用,因此我在这里:
https://course.fast.ai/deployment_amzn_sagemaker.html#deploy-to-sagemaker https://aws.amazon.com/getting-started/tutorials/build-train-deploy-machine-learning-model-sagemaker/
https://sagemaker.readthedocs.io/en/stable/pipeline.html
我的代码是这样的:
from sagemaker.pipeline import PipelineModel
from sagemaker.model import Model
s3_model_bucket = 'bucket'
s3_model_key_prefix = 'prefix'
data = 's3://{}/{}/{}'.format(s3_model_bucket, s3_model_key_prefix, 'model.tar.gz')
models = ss_model.create_model() # ss_model is my sagemaker.estimator
model = PipelineModel(name=data, role=role, models= [models])
ss_predictor = model.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge')
Run Code Online (Sandbox Code Playgroud)