使用Tensorflow op计算平均交并比,无需显式调用更新op?

2024-06-28 11:35:22 发布

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

发生这种情况:

import tensorflow as tf
labels = tf.constant([1,1,1])
predictions = tf.constant([0,0,1])
miou, conf_mat = tf.metrics.mean_iou(labels, predictions, 2)
sess = tf.InteractiveSession()
sess.run(tf.local_variables_initializer())

miou.eval()
>> 0.0
miou.eval()
>> 0.0

conf_mat.eval()
>> array([[0., 0.],
   [2., 1.]])
miou.eval()
>> 0.16666667

似乎我必须显式地调用update op(conf_mat)才能得到union上的平均交集。 有没有一种方法可以在不显式调用update操作的情况下计算结果?在


Tags: importlabelsconftftensorflowaseval情况
1条回答
网友
1楼 · 发布于 2024-06-28 11:35:22

是的,您可以使用^{}miou节点之前强制执行update_op

import tensorflow as tf
labels = tf.constant([1, 1, 1])
predictions = tf.constant([0, 0, 1])
miou, conf_mat = tf.metrics.mean_iou(labels, predictions, 2)
with tf.control_dependencies([tf.identity(conf_mat)]):
    miou = tf.identity(miou)
sess = tf.InteractiveSession()
sess.run(tf.local_variables_initializer())

print(miou.eval())

相关问题 更多 >