【发布时间】:2019-12-17 11:18:15
【问题描述】:
我正在尝试将使用 tensorflow 训练的对象检测模型部署到 sagemaker。我能够在模型创建期间在不指定任何入口点的情况下部署它,但事实证明这样做仅适用于小尺寸图像(Sagemaker 的限制为 5MB)。我用于此的代码如下:
from sagemaker.tensorflow.serving import Model
# Initialize model ...
model = Model(
model_data= s3_path_for_model,
role=sagemaker_role,
framework_version="1.14",
env=env)
# Deploy model ...
predictor = model.deploy(initial_instance_count=1,
instance_type='ml.t2.medium')
# Test using an image ...
import cv2
import numpy as np
image_content = cv2.imread("PATH_TO_IMAGE",
1).astype('uint8').tolist()
body = {"instances": [{"inputs": image_content}]}
# Works fine for small images ...
# I get predictions perfectly with this ...
results = predictor.predict(body)
所以,我搜索了一下,发现我需要为Model() 传递一个entry_point 才能预测更大的图像。比如:
model = Model(
entry_point="inference.py",
dependencies=["requirements.txt"],
model_data= s3_path_for_model,
role=sagemaker_role,
framework_version="1.14",
env=env
)
但是这样做会产生 FileNotFoundError: [Errno 2] No such file or directory: 'inference.py'。请在这里提供一点帮助。我正在使用sagemaker-python-sdk。
我的文件夹结构如下:
model
|__ 001
|__saved_model.pb
|__variables
|__<contents here>
|__ code
|__inference.py
|__requirements.txt
注意:我也试过,./code/inference.py 和 /code/inference.py。
【问题讨论】:
-
嗨,Pramesh,你能解决这个问题吗?
-
@MLDev 是的,我相信我能够做到这一点。但是,老实说,我再也不想经历那种痛苦了。我为此写了一篇博客。我希望这有帮助。 prameshbajra.github.io/aws/sagemaker/prediction/detection/…
标签: python amazon-web-services tensorflow tensorflow-serving amazon-sagemaker