amazon-web-services - 如何部署先前使用 Amazon Sagemaker 训练并存储在 S3 存储桶中的现有 pytorch 模型
问题描述
我使用 SageMaker 训练了一个 Pytorch 模型,该模型现在存储在 S3 存储桶中。我正在尝试检索该模型并进行部署。
这是我正在使用的代码:
estimator = sagemaker.model.FrameworkModel(
model_data= #link to model location in s3
image= # image
role=role,
entry_point='train.py',
source_dir='pytorch_source',
sagemaker_session = sagemaker_session
)
predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")
但是在部署过程之后(似乎运行顺利),预测器只是一个 NoneType。我在日志中没有发现任何奇怪的消息...
我还使用以下代码进行了另一次尝试:
estimator = PyTorchModel(model_data= #link to model location in s3
role=role,
image= #image
entry_point='pytorch_source/train.py',
predictor_cls = 'pytorch_source/train.py',
framework_version = '1.1.0')
predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")
但它甚至没有完成部署。
有人能帮忙吗?
解决方案
我实际上使用 PyTorchModel 解决了以下设置:
estimator = PyTorchModel(model_data='#path to model,
role=role,
source_dir='pytorch_source',
entry_point='deploy.py',
predictor_cls = ImgPredictor,
framework_version = '1.1.0')
ImgPredictor 在哪里
from sagemaker.predictor import RealTimePredictor, json_deserializer
class ImgPredictor(RealTimePredictor):
def __init__(self, endpoint_name, sagemaker_session):
super(ImgPredictor, self).__init__(endpoint_name, sagemaker_session, content_type='application/x-image',
deserializer = json_deserializer ,accept='application/json')
deploy.py 包含所需的函数 input_fn、output_fn、model_fn 和 predict_fn。此外,源目录中缺少 requirements.txt 文件。
推荐阅读
- docker - 将文件从主机挂载到 Docker 容器
- java - 设置 Java 应用程序以使用实时或测试系统
- puppeteer - 在 AWS 工作区上安装 Puppeteer - SELF_SIGNED_CERT_IN_CHAIN 时出错
- microsoft-graph-api - 为什么我在使用 Microsoft Graph Api 路由 GET /sites/{site-id}/pages 时突然收到 invalidRequest?
- javascript - aws lambda中的节点execFile python脚本
- javascript - 为什么 JavaScript 中的 "5" + 2+3 和 2+3+ "5" 不同?
- ubuntu - 谷歌云 ubuntu 虚拟服务器 - 无论如何都超过了 tweepy 速率限制
- python - 什么更好?:删除 tkinter 画布的所有元素并重新绘制它们,或者使用移动更新元素?
- jenkins - 在 Jenkins 中“剥离”声纳网络钩子数据
- javascript - 如何在javascript中增加数据索引