代码之家  ›  专栏  ›  技术社区  ›  Austin

TensorFlow以B64而不是Numpy数组的形式发送数据

  •  0
  • Austin  · 技术社区  · 6 年前

    我在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: ... 错误。不确定这是否不受支持,或者我只是做得不正确。

    1 回复  |  直到 6 年前
        1
  •  1
  •   sniggatooth    6 年前

    我已经和AWS支持人员讨论过这个问题(参见 More efficient way to send a request than JSON to deployed tensorflow model in Sagemaker? )

    他们建议有可能传入一个自定义输入,该输入将由服务容器使用,在该容器中可以解包压缩格式(如protobuf)。

    我将很快对此进行测试,希望这些东西能够工作,因为它将为输入处理增加很多灵活性。

    推荐文章