我在Sagemaker端点中有一个TensorFlow服务容器。我可以将一批图像作为一个麻木的数组,然后像这样返回预测:
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
这样做的有效载荷很大。我想知道,有没有一种方法可以以更压缩的格式发送这个?
我试过用
base64
和
json.dumps
但是不能过去
Invalid argument: JSON Value: ...
错误。不确定这是否不受支持,或者我只是做得不正确。