Java Tensorflow 服务预测客户端太慢
Java Tensorflow Serving Prediction Client Too Slow
我创建了一个 tensorflow
对象检测模型,并使用 tensorflow
服务为它提供服务。我创建了一个 python 客户端来测试服务模型,它需要大约 40 毫秒的时间来接收所有预测。
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));
实际问题是,
我正在通过网络发送所有图像像素(这是个坏主意)。现在,将输入更改为编码图像使其速度更快。
我创建了一个 tensorflow
对象检测模型,并使用 tensorflow
服务为它提供服务。我创建了一个 python 客户端来测试服务模型,它需要大约 40 毫秒的时间来接收所有预测。
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));
实际问题是,
我正在通过网络发送所有图像像素(这是个坏主意)。现在,将输入更改为编码图像使其速度更快。