2017-08-07 137 views
0

我正好具有this问题:如何从PredictResponse对象获取float_val?

运行在tensorflow-服务模型的预测后,我又回到这个PredictResponse对象作为输出:

outputs { 
    key: "scores" 
    value { 
    dtype: DT_FLOAT 
    tensor_shape { 
     dim { 
     size: 1 
     } 
     dim { 
     size: 2 
     } 
    } 
    float_val: 0.407728463411 
    float_val: 0.592271506786 
    }  
} 

至于建议中的这个问题,我。尝试使用: result.outputs [ '输出'] float_val

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

它是由该p产生代码的灵感来自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 

在此先感谢!

回答

3

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

为了将来的参考,documentation for the python bindings to protocol buffers解释了这个问题和其他问题。

+0

谢谢!我编辑它,因为我不得不使用result.outputs ['scores']。float_val [0]'而不是'result.outputs ['outputs']。float_val [0]' '钥匙'说'分数'。 –