【发布时间】:2019-12-07 21:27:41
【问题描述】:
我正在尝试为我的模型(语言分类)创建推理应用程序,但我收到错误 Channel object has no attribute unary_unary。我在任何地方都找不到关于这个问题的任何信息,因此这篇文章。我对 python 和 tensorflow 领域很陌生,我还在学习。
错误日志如下所示(最后几行)
2019-07-30T12:34:12.24+0200 [APP/PROC/WEB/0] ERR File "app.py", line 189, in do_inference
2019-07-30T12:34:12.24+0200 [APP/PROC/WEB/0] ERR stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
2019-07-30T12:34:12.24+0200 [APP/PROC/WEB/0] ERR File "/home/vcap/deps/0/python/lib/python3.6/site-packages/tensorflow_serving/apis/prediction_service_pb2_grpc.py", line 40, in __init__
2019-07-30T12:34:12.24+0200 [APP/PROC/WEB/0] ERR self.Classify = channel.unary_unary(
2019-07-30T12:34:12.24+0200 [APP/PROC/WEB/0] ERR AttributeError: 'Channel' object has no attribute 'unary_unary'
我正在使用烧瓶创建使用模型的 Web 服务。
@app.route('/LangDet', methods=['POST'])
def do_inference():
# get deployed model details
token = get_access_token()
model_name = request.path[1:]
query_string = {"modelName": model_name}
headers = {
'Authorization': token
}
res = requests.get(deployment_url, headers=headers, params=query_string)
model_info = json.loads(res.text)
if int(model_info["count"]) < 1:
return Response('404 Not Found: Model ' + model_name + ' is unavailable.', status=404)
else:
latest_version = [0, 0]
for index, model in enumerate(model_info["modelServers"]):
if int(model["specs"]["models"][0]["modelVersion"]) > latest_version[0]:
latest_version = [int(model["specs"]["models"][0]["modelVersion"]), index]
model_host = model_info["modelServers"][latest_version[1]]["endpoints"][0]
credentials = implementations.ssl_channel_credentials(root_certificates=bytes(model_host["caCrt"], 'ascii'))
channel = implementations.secure_channel(str(model_host["host"]), int(model_host["port"]), credentials)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
在声明存根后,应用程序抛出异常。这里似乎有什么问题,我可以做些什么来解决它?
【问题讨论】:
-
您能否提供有关您已安装的软件包的更多信息?
pip freeze的输出会很有帮助。如果您可以在第 49 行之前在/home/vcap/deps/0/python/lib/python3.6/site-packages/tensorflow_serving/apis/prediction_service_pb2_grpc.py中打印出channel和dir(channel),那也将非常有帮助。 -
我已经解决了这个问题。问题是我没有使用 grpc 创建通道,而是使用 grpc.beta 实现,它没有这样的参数。
标签: python-3.x tensorflow flask tensorflow-serving grpc-python