gpt4 book ai didi

python - 谁能告诉我如何使用tensorflow iou函数?

转载 作者:行者123 更新时间:2023-12-01 00:49:20 26 4
gpt4 key购买 nike

我想使用tensorflow的mean_iou函数并编写如下示例代码;但它给了我错误消息

尝试使用未初始化的值mean_iou_5/total_confusion_matrix [[{{节点mean_iou_5/total_confusion_matrix/read}}]]

谁能告诉我如何使用tensorflow的mean_iou函数?

谢谢。

labels1 = tf.convert_to_tensor([[3,1,2],[2,3,1]],tf.int32)
pred = tf.convert_to_tensor ([[3,1,2],[2,3,1]],tf.int32)

test,conf_mat = tf.metrics.mean_iou(labels = labels1, predictions = pred, num_classes = 3)
init_op = tf.global_variables_initializer()

with tf.Session() as sess:
init_op.run()
print('test',sess.run(test))

最佳答案

取自 StackOverflow 答案:https://stackoverflow.com/a/49326455/9820369

# y_pred and y_true are np.arrays of shape [1, size, channels]
with tf.Session() as sess:
ypredT = tf.constant(np.argmax(y_pred, axis=-1))
ytrueT = tf.constant(np.argmax(y_true, axis=-1))
iou,conf_mat = tf.metrics.mean_iou(ytrueT, ypredT, num_classes=3)
sess.run(tf.local_variables_initializer())
sess.run([conf_mat])
miou = sess.run([iou])
print(miou)

关于python - 谁能告诉我如何使用tensorflow iou函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56694234/

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