Tensorflow 服务:请求失败,对象没有属性“unary_unary" [英] Tensorflow serving: request fails with object has no attribute 'unary_unary
问题描述
我正在使用 TensorFlow 构建一个 CNN 文本分类器,我想将其加载到 tensorflow 服务中并使用服务 api 进行查询.当我在 grcp 存根上调用 Predict() 方法时,我收到此错误:AttributeError: 'grpc._cython.cygrpc.Channel' object has no attribute 'unary_unary'
I'm building a CNN text classifier using TensorFlow which I want to load in tensorflow-serving and query using the serving apis. When I call the Predict() method on the grcp stub I receive this error: AttributeError: 'grpc._cython.cygrpc.Channel' object has no attribute 'unary_unary'
迄今为止我所做的:我已经成功地训练并导出了一个适合服务的模型(即,验证了签名并使用 tf.Saver 我可以成功地返回一个预测).我也可以在 tensorflow_model_server 中加载模型而不会出错.
What I've done to date: I have successfully trained and exported a model suitable for serving (i.e., the signatures are verified and using tf.Saver I can successfully return a prediction). I can also load the model in tensorflow_model_server without error.
以下是客户端代码片段(为了便于阅读而进行了简化):
Here is a snippet of the client code (simplified for readability):
with tf.Session() as sess:
host = FLAGS.server
channel = grpc.insecure_channel('localhost:9001')
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = 'predict_text'
request.model_spec.signature_name = 'predict_text'
x_text = ["space"]
# restore vocab processor
# then create a ndarray with transform_fit using the vocabulary
vocab = learn.preprocessing.VocabularyProcessor.restore('/some_path/model_export/1/assets/vocab')
x = np.array(list(vocab.fit_transform(x_text)))
# data
temp_data = tf.contrib.util.make_tensor_proto(x, shape=[1, 15], verify_shape=True)
request.inputs['input'].CopyFrom(tf.contrib.util.make_tensor_proto(x, shape=[1, 15], verify_shape=True))
# get classification prediction
result = stub.Predict(request, 5.0)
我违反规则的地方:当 pip install 不受官方支持时,我在 Python 3.5.3 中使用 tensorflow-serving-apis.各种帖子(例如:https://github.com/tensorflow/serving/issues/581) 报告称,在 Python 3 中使用 tensorflow-serving 已成功.我已经从 pypi (https://pypi.python.org/pypi/tensorflow-serving-api/1.5.0)和手动粘贴到环境中.
Where I'm bending the rules: I am using tensorflow-serving-apis in Python 3.5.3 when pip install is not officially supported. Various posts (example: https://github.com/tensorflow/serving/issues/581) have reported that using tensorflow-serving with Python 3 has been successful. I have downloaded tensorflow-serving-apis package from pypi (https://pypi.python.org/pypi/tensorflow-serving-api/1.5.0)and manually pasted into the environment.
Versions: tensorflow: 1.5.0, tensorflow-serving-apis: 1.5.0, grpcio: 1.9.0rc3, grcpio-tools: 1.9.0rcs, protobuf: 3.5.1 (所有其他依赖版本已经过验证,但正在为简洁起见不包括在内 - 如果它们有用,很乐意添加)
Versions: tensorflow: 1.5.0, tensorflow-serving-apis: 1.5.0, grpcio: 1.9.0rc3, grcpio-tools: 1.9.0rcs, protobuf: 3.5.1 (all other dependency version have been verified but are not included for brevity -- happy to add if they have utility)
环境:Linux Mint 17 Qiana;x64,Python 3.5.3
Environment: Linux Mint 17 Qiana; x64, Python 3.5.3
调查:一个 github 问题(https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2258) 表示触发此错误的历史包与 grpc beta 相关.
Investigations: A github issue (https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2258) indicated that a historical package triggered this error was related to grpc beta.
我缺少哪些数据、学习或实施?
What data or learning or implementation am I missing?
推荐答案
beta_create_PredictionService_stub()
已弃用.试试这个:
from tensorflow_serving.apis import prediction_service_pb2_grpc
...
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
这篇关于Tensorflow 服务:请求失败,对象没有属性“unary_unary"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!