[英]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.