【发布时间】:2023-03-17 02:00:01
【问题描述】:
- tensorflow-gpu 1.10.0
- 张量流服务器 1.10.0
我已经部署了一个服务于多个模型的 tensorflow 服务器。
客户端代码就像client.py这个,我调用predict函数。
channel = implementations.insecure_channel(host, port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
def predict(data, shape, model_name, signature_name="predict"):
request.model_spec.name = model_name
request.model_spec.signature_name = signature_name
request.inputs['image'].CopyFrom(tf.contrib.util.make_tensor_proto(data, shape=shape))
result = stub.Predict(request, 10.0)
return result.outputs['prediction'].float_val[0]
我有大约 100 个具有相同配置的客户端。
下面是调用predict函数的示例代码:
from client import predict
while True:
print(predict(data, shape, model_name))
# time.sleep some while
首先,当我运行客户端代码时,我可以正确收到响应。 但几个小时后,客户端因错误而崩溃
_Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Socket closed)
我尝试将我的客户端代码修改为
def predict(data, shape, model_name, signature_name="predict"):
channel = implementations.insecure_channel(host, port)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = model_name
request.model_spec.signature_name = signature_name
request.inputs['image'].CopyFrom(tf.contrib.util.make_tensor_proto(data, shape=shape))
result = stub.Predict(request, 10.0)
return result.outputs['prediction'].float_val[0]
这意味着每次调用predict 函数时,我都会尝试与 tfs 服务器建立连接。但是这段代码也像以前一样失败了。
那么我应该怎么处理这种情况呢?
【问题讨论】:
标签: python tensorflow grpc tensorflow-serving grpc-python