如何从PredictResponse对象获取浮点值?

2024-10-01 15:29:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了this问题:

在对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
  }    
}

正如问题中所建议的,我尝试使用: 结果.输出['outputs']浮点值

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

它是由这段代码产生的,灵感来自《盗梦空间》_客户端.py示例:

^{pr2}$

提前谢谢!在


Tags: 对象key模型sizevaluetensorflowdtval
2条回答

result.outputs['scores'].float_val[0]和{}是此响应中的浮点值。在

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

如果您有多个输出的名称存储在output_names列表中,您可以执行以下操作来创建一个以输出名称为键的字典和一个包含模型返回值的列表。在

results = dict()
for output in output_names:
    results[output] = response.outputs[output].float_val

相关问题 更多 >

    热门问题