Python RuntimeError:tf.metrics.mean_iou在启用“急切执行”时不受支持
我试图得到两组边界框之间的平均IOU度量。我遇到了以下错误: RuntimeError:tf.metrics.mean_iou在启用急切执行时不受支持 引发错误的可复制代码:Python RuntimeError:tf.metrics.mean_iou在启用“急切执行”时不受支持,python,tensorflow,machine-learning,Python,Tensorflow,Machine Learning,我试图得到两组边界框之间的平均IOU度量。我遇到了以下错误: RuntimeError:tf.metrics.mean_iou在启用急切执行时不受支持 引发错误的可复制代码: import tensorflow as tf a = [[0.462, 0.465, 0.492, 0.58], [0.435, 0.385, 0.462, 0.467], [0.586, 0.449, 0.627, 0.616], [0.431, 0.671, 0.494, 0.8],
import tensorflow as tf
a = [[0.462, 0.465, 0.492, 0.58],
[0.435, 0.385, 0.462, 0.467],
[0.586, 0.449, 0.627, 0.616],
[0.431, 0.671, 0.494, 0.8],
[0.519, 0.282, 0.586, 0.449]]
b = [[0.465, 0.467, 0.491, 0.586],
[0.432, 0.488, 0.464, 0.59],
[0.585, 0.442, 0.633, 0.625],
[0.429, 0.664, 0.493, 0.805],
[0.524, 0.502, 0.594, 0.642]]
tf.compat.v1.metrics.mean_iou(a, b, num_classes=1)
我的选择是什么?我能够让它工作:
import tensorflow as tf
a = [[0.462, 0.465, 0.492, 0.58],
[0.435, 0.385, 0.462, 0.467],
[0.586, 0.449, 0.627, 0.616],
[0.431, 0.671, 0.494, 0.8],
[0.519, 0.282, 0.586, 0.449]]
b = [[0.465, 0.467, 0.491, 0.586],
[0.432, 0.488, 0.464, 0.59],
[0.585, 0.442, 0.633, 0.625],
[0.429, 0.664, 0.493, 0.805],
[0.524, 0.502, 0.594, 0.642]]
metric = tf.keras.metrics.MeanIoU(num_classes=1)
print(metric(a, b))
>> tf.Tensor(1.0, shape=(), dtype=float32)
文档页面更详细地解释了MeanIoU度量,但我认为上面的代码片段适合您