【问题标题】:Tensorflow serving: request fails with object has no attribute 'unary_unaryTensorflow服务:请求失败,对象没有属性'unary_unary
【发布时间】:2018-01-30 19:46:35
【问题描述】:

我正在使用 TensorFlow 构建一个 CNN 文本分类器,我想将其加载到 tensorflow-serving 中并使用服务 api 进行查询。当我在 grcp 存根上调用 Predict() 方法时,我收到此错误:AttributeError: 'grpc._cython.cygrpc.Channel' object has no attribute 'unary_unary'

到目前为止我做了什么: 我已经成功训练并导出了一个适合服务的模型(即验证签名并使用 tf.Saver 我可以成功返回预测)。我也可以在 tensorflow_model_server 中加载模型而不会出错。

这是客户端代码的 sn-p(为便于阅读而简化):

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下载了tensorflow-serving-apis包(https://pypi.python.org/pypi/tensorflow-serving-api/1.5.0)and手动粘贴到环境中。

版本: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 有关。

我缺少哪些数据或学习或实施?

【问题讨论】:

  • 有人有什么见解吗?任何指针都非常感谢。
  • 想知道您是否在这方面取得了任何进展?

标签: python-3.x tensorflow tensorflow-serving


【解决方案1】:

beta_create_PredictionService_stub() 已弃用。试试这个:

from tensorflow_serving.apis import prediction_service_pb2_grpc
...
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)

【讨论】:

  • 要实现这一点,请确保您使用的是 grcp 1.36,如果不是,请使用以下命令 pip install -U grcpio 另外,请确保将您的频道对象声明为 grpc.insecure_channel('your_url : the_port')
【解决方案2】:

尝试使用grpc.beta.implementations.insecure_channel 而不是grpc.insecure_channel

参见示例代码here

【讨论】:

    猜你喜欢
    • 2021-04-28
    • 2014-06-26
    • 2015-08-17
    • 2023-03-26
    • 2012-08-22
    • 2018-06-20
    • 2019-12-07
    • 1970-01-01
    • 2019-01-24
    相关资源
    最近更新 更多