【问题标题】:tensorflow tf.metrics张量流 tf.metrics
【发布时间】:2018-02-01 12:52:26
【问题描述】:

我对 tensorflow 指标 (tf.metrics) 有一些疑问。有一些可用的指标,如准确度、精度、误报等。

根据API精度等至少需要两个参数:

precision("ground truth values", "predicted values")

在“session.run”之后,我有一个带有一些张量的结果字典,见下图

result dict

detection boxes

groundtruth box

detection scores

如何使用这些值来计算准确度、精确度、假阳性等?

我尝试了以下方法:

prec = tf.metrics.precision(result_dict['groundtruth_boxes'],  result_dict['detection_boxes'][0])

但我收到以下错误:

ValueError: Can not squeeze dim[1], expected a dimension of 1, got 4 for 'precision/remove_squeezable_dimensions/Squeeze' (op: 'Squeeze') with input shapes: [1,4].

无论如何我的尝试毫无意义,因为计算精度需要“真阳性”和“假阳性”。

【问题讨论】:

  • 请不要链接到文本截图...直接将文本粘贴到您的问题中。
  • 没有人可以帮助我???

标签: python-3.x tensorflow object-detection-api


【解决方案1】:

首先,tf.metrics 最适用于计算多批次的运行指标。因为他们需要在sess.run() 调用中保持状态,所以它们并不像某些人想象的那么简单。这是一篇很好的文章,解释了它们是如何工作的:http://ronny.rest/blog/post_2017_09_11_tf_metrics/

对于您的问题,tf.metrics.precision 的参数必须(有效地)是布尔张量。您不能直接提供边界框。例如,以下将打印1.0

prediction = tf.constant([1., 1., 2., 2.])
label = tf.constant([1., 1., 3., 3.])
precision, update_op = tf.metrics.precision(label, prediction)

with tf.Session() as sess:
  sess.run(tf.local_variables_initializer())
  sess.run(update_op)
  print sess.run(precision)

因为23 都不是零。

您需要自己比较边界框(例如,为每个框做tf.reduce_all(tf.equal(expected_box, predicted_box))),以便每个框都有一个True/False 标量。所有这些放入向量中的标量将成为tf.metrics.precisionpredictions 参数。 labels 参数是 True 的张量,与 predictions 大小相同。

【讨论】:

    猜你喜欢
    • 2018-01-23
    • 2017-11-05
    • 2017-12-01
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 2019-01-08
    • 2017-07-10
    相关资源
    最近更新 更多