[英]How to store a .tar.gz formatted model to AWS SageMaker and use it as a deployed model?
要使用现有的模型对象,只需将其打包在 .tar.gz 中并存储在 S3 中。
打包后,您可以使用 sage maker API 通过 sage maker notebooks \\studio 或 terraform 部署它。
这是 .tar.gz 应该遵循的结构。
|----- preprocessing.joblib # multiple model objects included here
|----- model.joblib
|----- code
|----- inference.py # used for custom transformation \ loading model etc.
|----- requirements.txt # can be ran to include dependencies not in the docker image
前任。
tar czvf model.tar.gz. model_xgb.joblib preprocessor.joblib code
打包模型后,您可以通过将模型加载到模型类之一然后部署它来创建端点。
from sagemaker.amazon.amazon_estimator import get_image_uri
from sagemaker.model import Model
from sagemaker.pipeline import PipelineModel
container=sagemaker.image_uris.retrieve("xgboost", boto3.Session().region_name, "0.90-1")
print(container)
model_name = 'some_model_123'
model_location= "s3://somebucket/somemodelpath/someversion/model.tar.gz"
env = {
'SAGEMAKER_REQUIREMENTS': 'requirements.txt',
'SAGEMAKER_PROGRAM': 'inference.py',
'SAGEMAKER_SUBMIT_DIRECTORY' : model_location
}
model= Model(
model_data=model_location,
image_uri =container,
env = env
)
endpoint_name = model_name
pipeline_model = PipelineModel(name=model_name,
role=role,
models=[
model
])
pm = pipeline_model.deploy(initial_instance_count=1, instance_type="ml.c4.xlarge", endpoint_name=endpoint_name)
这是一个自带模型的参考,它帮助了我很多。 https://medium.com/geekculture/84af8989d065
这是对我在挣扎时发布的类似问题的参考。 如何处理 sagemaker 端点中的自定义转换/推理和要求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.