我编写了python客户端,用于在TensorProto中转换我的图像,并在预测请求中发送该图像。但是,我需要用Java编写类似的客户端。
下面是我的python代码:
def run():
host= "localhost"
port= "9000"
request = tensorflow__serving_dot_apis_dot_predict__pb2.PredictRequest()
channel = setup_channel(host, int(port), None)
stub = tensorflow__serving_dot_apis_dot_prediction_service__pb2.beta_create_PredictionService_stub(channel,
metadata_transformer=create_metadata_transformer())
for image_path in TEST_IMAGE_PATHS:
image = skimage.io.imread(image_path)
request = tensorflow__serving_dot_apis_dot_predict__pb2.PredictRequest()
request.model_spec.name = "segmentation-model"
request.model_spec.version.value = 1
request.inputs['images'].CopyFrom(
tf.contrib.util.make_tensor_proto(image))
response = stub.Predict(request, 200)
从skimage.io读取后,我的输入是一个numpy形状的数组(126,100,3) 我想在Java中实现相同的目标。到目前为止,我已经尝试在互联网上搜索不成功。
如果有人能够提供帮助,我将非常感谢。
--------更新---------
已经实现。