我想了解从 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/