Sagemaker tensorflow 端点在被调用进行预测时不调用 input_handler
Sagemaker tensorflow endpoint not calling the input_handler when being invoked for a prediction
我正在通过 entry point
参数
使用自定义 inference.py
脚本部署 tensorflow.serving
端点
model = Model(role='xxx',
framework_version='2.2.0',
entry_point='inference.py',
model_data='xxx')
predictor = model.deploy(instance_type='xxx',
initial_instance_count=1,
endpoint_name='xxx')
inference.py 包含一个 input_handler
和一个 output_handler
函数,但是当我调用预测时:
model = Predictor(endpoint_name='xxx')
url = 'xxx'
input = {
'instances': [url]
}
predictions = model.predict(input)
我得到以下 error
:
botocore.errorfactory.ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError):从模型收到客户端错误 (400),消息为“{”error“:”无法处理元素: 'instances' 列表中的 0 个。错误:参数无效:JSON 值:“xxx”类型:字符串不是预期类型:float"}"
似乎该函数从未调用 inference.py 脚本中的 input_handler
函数。你知道为什么会这样吗?
感谢 AWS 支持发现问题:
我创建的端点已经有同名的端点配置,但新配置未被使用。
我正在添加此错误消息的另一个可能原因,因为我花了一些时间来解决这个问题。
我使用的是不同的 sagemaker api 版本(1.x 和 2.x)。
对于较新的 sagemaker tf 容器,处理程序的名称已从 input_fn() 更改为 input_handler()。
因此从未调用 input_fn() 并且从未处理过特殊输入类型。
详情见:https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/upgrade_from_legacy.html
也许这对某人有帮助。
我正在通过 entry point
参数
inference.py
脚本部署 tensorflow.serving
端点
model = Model(role='xxx',
framework_version='2.2.0',
entry_point='inference.py',
model_data='xxx')
predictor = model.deploy(instance_type='xxx',
initial_instance_count=1,
endpoint_name='xxx')
inference.py 包含一个 input_handler
和一个 output_handler
函数,但是当我调用预测时:
model = Predictor(endpoint_name='xxx')
url = 'xxx'
input = {
'instances': [url]
}
predictions = model.predict(input)
我得到以下 error
:
botocore.errorfactory.ModelError:调用 InvokeEndpoint 操作时发生错误 (ModelError):从模型收到客户端错误 (400),消息为“{”error“:”无法处理元素: 'instances' 列表中的 0 个。错误:参数无效:JSON 值:“xxx”类型:字符串不是预期类型:float"}"
似乎该函数从未调用 inference.py 脚本中的 input_handler
函数。你知道为什么会这样吗?
感谢 AWS 支持发现问题:
我创建的端点已经有同名的端点配置,但新配置未被使用。
我正在添加此错误消息的另一个可能原因,因为我花了一些时间来解决这个问题。
我使用的是不同的 sagemaker api 版本(1.x 和 2.x)。
对于较新的 sagemaker tf 容器,处理程序的名称已从 input_fn() 更改为 input_handler()。
因此从未调用 input_fn() 并且从未处理过特殊输入类型。
详情见:https://sagemaker.readthedocs.io/en/stable/frameworks/tensorflow/upgrade_from_legacy.html
也许这对某人有帮助。