TensorFlow Serving 将数据作为 b64 而不是 Numpy 数组发送
TensorFlow Serving send data as b64 instead of Numpy Array
我在 SageMaker 端点中有一个 TensorFlow Serving 容器。我能够将一批图像作为 Numpy 数组并得到这样的预测:
import numpy as np
import sagemaker
from sagemaker.predictor import json_serializer, json_deserializer
image = np.random.uniform(low=-1.0, high=1.0, size=(1,128,128,3)).astype(np.float32)
image = {'instances': image}
image = json_serializer(image)
request_args = {}
request_args['Body'] = image
request_args['EndpointName'] = endpoint_name
request_args['ContentType'] = 'application/json'
request_args['Accept'] = 'application/json'
# works successfully
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
response_body = response['Body']
predictions = json_deserializer(response_body, response['ContentType'])
request_args
payload 的大小是很大的这样做。我想知道,有没有办法以更压缩的格式发送它?
我尝试过 base64
和 json.dumps
,但无法克服 Invalid argument: JSON Value: ...
错误。不确定这是否不受支持,或者我只是做错了。
我已经与 AWS 支持人员讨论过此事(请参阅 More efficient way to send a request than JSON to deployed tensorflow model in Sagemaker?)。
他们建议可以传入一个自定义 input_fn,服务容器将使用它来解压压缩格式(例如 protobuf)。
我很快就会对此进行测试,希望它能正常工作,因为它会为输入处理增加很多灵活性。
我在 SageMaker 端点中有一个 TensorFlow Serving 容器。我能够将一批图像作为 Numpy 数组并得到这样的预测:
import numpy as np
import sagemaker
from sagemaker.predictor import json_serializer, json_deserializer
image = np.random.uniform(low=-1.0, high=1.0, size=(1,128,128,3)).astype(np.float32)
image = {'instances': image}
image = json_serializer(image)
request_args = {}
request_args['Body'] = image
request_args['EndpointName'] = endpoint_name
request_args['ContentType'] = 'application/json'
request_args['Accept'] = 'application/json'
# works successfully
response = sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args)
response_body = response['Body']
predictions = json_deserializer(response_body, response['ContentType'])
request_args
payload 的大小是很大的这样做。我想知道,有没有办法以更压缩的格式发送它?
我尝试过 base64
和 json.dumps
,但无法克服 Invalid argument: JSON Value: ...
错误。不确定这是否不受支持,或者我只是做错了。
我已经与 AWS 支持人员讨论过此事(请参阅 More efficient way to send a request than JSON to deployed tensorflow model in Sagemaker?)。
他们建议可以传入一个自定义 input_fn,服务容器将使用它来解压压缩格式(例如 protobuf)。
我很快就会对此进行测试,希望它能正常工作,因为它会为输入处理增加很多灵活性。