python - tf.metrics.accuracy 返回的第一个值代表什么

标签 python tensorflow

我想了解从 tf.metrics.accuracy 返回的值

考虑这个最小的例子:

predictions = tf.constant([[1,0,1], [1,0,1]], dtype=tf.int32)
labels = tf.constant([[0,0,1], [1,0,1]], dtype=tf.int32)

acc = tf.metrics.accuracy(labels, predictions)

with tf.Session() as sess:
  sess.run(tf.local_variables_initializer())
  res = sess.run(acc)
print(res) 

输出:

(0.0, 0.8333333)

第二个值是我所期望的(我们有 5/6 个值,其中 predictions == labels 所以 5/6 ~= 0.83),但第一个零值对我来说是个谜?

TensorFlow docs有话要说:

Returns:

  • accuracy: A Tensor representing the accuracy, the value of total divided by count.
  • update_op: An operation that increments the total and count variables appropriately and whose value matches accuracy.

但这表明两个返回操作的值都应该为 0.83,不是吗? (但是返回 2 个操作有什么意义呢?!)

感觉我错过了一些基本的东西!

最佳答案

根据 tensorflow 代码和描述,第一个值是在没有最新批处理数据的情况下计算的精度(在流数据的情况下),第二个值是使用所有数据计算的最终精度。 Tensorflow 使用它来进行数据的流处理。

关于python - tf.metrics.accuracy 返回的第一个值代表什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53362642/

相关文章:

python - 记录和清除文件

python - Tensorflow:如何赋予变量范围

protocol-buffers - 有没有关于如何生成包含经过训练的 TensorFlow 图的 protobuf 文件的示例

python - TensorFlow:如何使用 'tf.data' 而不是 'load_csv_without_header'?

python - 我在 matplotlib (python) 中有一个带有误差线的条形图,但我想要误差线在中间。我该怎么做呢?谢谢

Python 2to3 不改变 #!/usr/bin/python

python - 如何将机器学习算法连接到数据库

python - Numpy:从两个向量(或一个向量本身)的笛卡尔积创建一个矩阵,同时将一个函数应用于所有对

python-3.x - TensorFlow 导入错误 : TensorFlow import error

tensorflow - tf.data group_by_window() 无需首先迭代完整的数据集