C. *_*ler 5 python-3.x tensorflow tensorflow-serving
我正在使用TensorFlow构建CNN文本分类器,我想在Tensorflow服务中加载并使用服务API进行查询。当我在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)
Run Code Online (Sandbox Code Playgroud)
我在哪里弯腰规则:当正式不支持pip安装时,我在Python 3.5.3中使用tensorflow-serving-apis。各种帖子(例如:https : //github.com/tensorflow/serving/issues/581)都报告说,将tensorflow-serving与Python 3结合使用已成功。我已经从pypi(https://pypi.python.org/pypi/tensorflow-serving-api/1.5.0)下载了tensorflow-serving-apis软件包,并手动粘贴到了环境中。
版本: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有关。
我缺少什么数据或学习或实施方法?
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |