2017-08-07 60 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]' '鑰匙'說'分數'。 –