如何从PredictResponse对象获取float_val?

Rod*_*una 0 python protocol-buffers tensorflow tensorflow-serving

我正好有这个问题:

在张量流服务模型上运行预测后,我得到了这个PredictResponse对象作为输出:

outputs {
  key: "scores"
  value {
    dtype: DT_FLOAT
    tensor_shape {
      dim {
        size: 1
      }
      dim {
        size: 2
      }
    }
    float_val: 0.407728463411
    float_val: 0.592271506786
  }    
}
Run Code Online (Sandbox Code Playgroud)

如该问题的建议,我尝试使用:result.outputs ['outputs']。float_val

但是它返回类型 <type google.protobuf.pyext._message.RepeatedScalarContainer>

它是由这段代码产生的,灵感来自inception_client.py示例:

channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
result = stub.Predict(request, 10.0)  # 10 secs timeout
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Ale*_*sos 5

result.outputs['scores'].float_val[0]并且result.outputs['scores'].float_val[1]是此响应中的浮点值。

供将来参考,有关与协议缓冲区的python绑定文档介绍了此问题和其他问题。