我已经使用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")但在部署过程之后(似乎运行得很顺利),predictor只是一个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")但它甚至不能完成部署。
有人能帮上忙吗?
发布于 2020-03-06 21:00:35
我实际上使用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文件。
https://stackoverflow.com/questions/60529048
复制相似问题