gpt4 book ai didi

python - 计算与 tensorflow 运算并集的平均交集而不显式调用更新运算?

转载 作者:行者123 更新时间:2023-12-01 09:14:40 25 4
gpt4 key购买 nike

发生这种情况:

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

看来我必须显式调用更新操作(conf_mat)才能获得并集的平均交集。有没有一种方法可以在不显式调用更新操作的情况下计算结果?

最佳答案

是的,您可以使用tf.control_depenencies强制在 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())

关于python - 计算与 tensorflow 运算并集的平均交集而不显式调用更新运算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51365073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com