我正在使用TensorFlow构建CNN文本分类器,我想使用服务apis加载tensorflow-serving和query . 当我在grcp存根上调用Predict()方法时,我收到此错误:AttributeError:'grpc._cython.cygrpc.Channel'对象没有属性'unary_unary'
到目前为止我做了什么:我已经成功地训练并导出了适合服务的模型(即,签名被验证并且使用tf.Saver我可以成功地返回预测) . 我也可以在tensorflow_model_server中加载模型而不会出错 .
以下是客户端代码的片段(为便于阅读而简化):
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)报告说,使用使用tensorflow服务的Python 3已经成功 . 我从pypi下载了tensorflow-serving-apis包(https://pypi.python.org/pypi/tensorflow-serving-api/1.5.0)andand)手动粘贴到环境中 .
版本:tensorflow:1.5.0,tensorflow-serving-apis:1.5.0,grpcio:1.9.0rc3,grcpio-tools:1.9.0rcs,protobuf:3.5.1(所有其他依赖版本已经过验证但不包括在内简洁 - 如果他们有实用性,很乐意添加)
环境:Linux Mint 17 Qiana; x64,Python 3.5.3
调查:github问题(https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2258)表明触发此错误的历史包与grpc beta有关 .
我错过了哪些数据或学习或实施?
1 回答
尝试使用
grpc.beta.implementations.insecure_channel
而不是grpc.insecure_channel
.请参见示例代码here .