如何解决将选择的或Joblib预训练的ML模型加载到Sagemaker并作为端点托管
如果我在使用咸菜或Joblib中有受过训练的模型。 可以说它的逻辑回归或XGBoost。
我希望在不运行培训的情况下将该模型托管在AWS Sagemaker中作为终端。 如何做到这一点。
#Lets Say myBucketName contains model.pkl
model = joblib.load('filename.pkl')
# X_test = Numpy Array
model.predict(X_test)
我对sklearn_estimator.fit('S3 Train,S3 Validate' )
不感兴趣,我拥有训练有素的模型
解决方法
以Scikit Learn为例,您可以从此公开演示https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/scikit_learn_randomforest/Sklearn_on_SageMaker_end2end.ipynb
中获得启发步骤1:将在S3中压缩的工件(例如joblib)保存在s3://<your path>/model.tar.gz
步骤2:使用反序列化功能model_fn
创建一个推理脚本。 (请注意,您还可以添加自定义推理功能input_fn
,predict_fn
,output_fn
,但对于scikit,默认功能正常工作)
%%writefile inference_script.py. # Jupiter command to create file in case you're in Jupiter
import joblib
import os
def model_fn(model_dir):
clf = joblib.load(os.path.join(model_dir,"model.joblib"))
return clf
第3步:创建将工件与正确的容器相关联的模型
from sagemaker.sklearn.model import SKLearnModel
model = SKLearnModel(
model_data='s3://<your path>/model.tar.gz',role='<your role>',entry_point='inference_script.py',framework_version='0.23-1')
第4步:部署!
model.deploy(
instance_type='ml.c5.large',# choose the right instance type
initial_instance_count=1)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。