繁体   English   中英

使用 protobuf 通过 GRPC 发送图像的最佳方式

[英]Best way to send image through GRPC using protobuf

我目前正在使用 python grpc。 我的目的是使用最小负载大小将图像发送到我的 GRPC 服务器。 我的原型如下所示:

message ImageBinaryRequest {
  // Image as bytes
  bytes image = 1;
}

我的客户像这样编码图像:

def get_binary_request():
    image = (np.random.rand(1080, 1920, 3) * 255).astype(np.uint8)
    return cv2.imencode(".jpg", image)[1].tobytes()


channel = grpc.insecure_channel(grpc_url)
stub = inference_pb2_grpc.InferenceAPIsServiceStub(channel)

response= stub.BenchmarkBinaryImage(
    benchmark_pb2.ImageBinaryRequest(image=get_binary_request())
)

我想知道这是否是通过 GRPC 序列化和映像的最佳方式? 由于有效负载大小与 REST 相同:

requests.post(http_url, data=get_binary_request())

这是发送图像的好方法。 gRPC 没有处理图像的固有方式。 它在底层使用与 REST 服务相同的 HTTP/2,因此预计大小具有可比性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM