Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 张量流服务响应_Python_Tensorflow_Tensorflow Serving - Fatal编程技术网

Python 张量流服务响应

Python 张量流服务响应,python,tensorflow,tensorflow-serving,Python,Tensorflow,Tensorflow Serving,我正在尝试与Tensorflow服务会话建立通信。 下面的代码可以工作,但有点慢。有什么办法可以改进吗?我怀疑问题出在第四行-输出是作为float_val元素的列表给出的,我需要将它们转换为float数组并对其进行重塑 有没有办法使服务器输出的形状正确? 我已经将输出签名定义如下(我认为这是正确的) 第一行使用函数打开到服务器的通道 def setup_channel(hostport): host, port = hostport.split(':') channel = impl

我正在尝试与Tensorflow服务会话建立通信。 下面的代码可以工作,但有点慢。有什么办法可以改进吗?我怀疑问题出在第四行-输出是作为float_val元素的列表给出的,我需要将它们转换为float数组并对其进行重塑

有没有办法使服务器输出的形状正确? 我已经将输出签名定义如下(我认为这是正确的)

第一行使用函数打开到服务器的通道

def setup_channel(hostport):
   host, port = hostport.split(':')
   channel = implementations.insecure_channel(host, int(port))
    stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
   request = predict_pb2.PredictRequest()
   request.model_spec.name = 'hg'
   request.model_spec.signature_name = 'predict_images'
   return stub, request
输出签名为:

tensor_info_x = tf.saved_model.utils.build_tensor_info(model.input_tensor)
tensor_info_y = tf.saved_model.utils.build_tensor_info(model.predict)

prediction_signature = (
    tf.saved_model.signature_def_utils.build_signature_def(
        inputs={'images': tensor_info_x},
        outputs={'scores': tensor_info_y},
        method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))**

模型预测的形状为(1,16,64,64)。

我不确定您如何处理您的
预测。未来(请求表单,5.0)
,但同步响应处理也应如此;tf提供了一个实用功能
make_ndarray

res = stub.Predict(request, timeout).outputs[tensor_name]
arr = tf.make_ndarray(res)
arr
将是正确DIM的np数组

其中,
tensor\u name
是您签名中定义的名称,例如

tf.saved_model.signature_def_utils.build_signature_def(
    inputs={'images': inp_tensor_info},
    outputs={'scores': out_tensor_info},
    method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME
)
需要

res = stub.Predict(request, timeout).outputs['scores']
arr = tf.make_ndarray(res)
res = stub.Predict(request, timeout).outputs['scores']
arr = tf.make_ndarray(res)