我需要将图像(numpy
数组),有关图像的其他元信息(例如高度,宽度等)从python grpc
客户端传递到python grpc
服务器。
我需要运行此方法。
import numpy as np
def predict(img, w, h):
# some operations
return img.shape[2], np.mean(img)
我查看了文档,但是protobuf中没有numpy
数组的兼容数据类型。
https://developers.google.com/protocol-buffers/docs/proto3
image_procedure.proto
syntax = "proto3";
// input image, width, height
message Image {
image_type image = 1;
int32 width = 2;
int32 height = 3;
}
// output prediction
message Prediction {
int32 channel = 4;
float mean = 5;
}
// service
service ImageProcedure {
rpc ImageMeanWH(Image) returns (Prediction) {}
}
如何将图像和其他相关数据发送到服务器并获得响应?
您总是可以将numpy数组编码为base64字符串,并将其传递给服务器。
您的.proto
文件应如下所示:
syntax = "proto3";
// input image, width, height
message B64Image {
string b64image = 1;
int32 width = 2;
int32 height = 3;
}
// output prediction
message Prediction {
int32 channel = 4;
float mean = 5;
}
// service
service ImageProcedure {
rpc ImageMeanWH(B64Image) returns (Prediction) {}
}