Java Tensorflow服务预测客户端太慢

时间:2017-08-28 11:02:23

标签: tensorflow object-detection grpc tensorflow-serving

我创建了一个tensorflow对象检测模型,并使用tensorflow服务来提供服务。我已经创建了一个python客户端来测试服务模型,并且需要大约40ms的时间来接收所有预测。

t1 = datetime.datetime.now()
result = stub.Predict(request, 60.0)  # 60 secs timeout
t2 = datetime.datetime.now()
print ((t2 - t1).microseconds / 1000)

现在,我的问题是当我在java上做同样的事情时,需要花费450到500毫秒的太多时间(大约10次)。

ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9000)
        .usePlaintext(true)
        .build();
PredictionServiceGrpc.PredictionServiceBlockingStub stub = PredictionServiceGrpc.newBlockingStub(channel);

......

Instant pre = Instant.now();
Predict.PredictResponse response = stub.predict(request);
Instant curr = Instant.now();
System.out.println("time " + ChronoUnit.MILLIS.between(pre,curr));

有人可以帮我解决这个问题吗?谢谢你提前。

1 个答案:

答案 0 :(得分:0)

实际问题是,

我通过网络发送所有图像像素(这是一个坏主意)。现在,将输入更改为编码图像使其更快。