看过有解释是说这是Label的问题,将Label改为 [m* n* 1] 的灰度图像即可,但有些情况下即使将Label图像改为灰度图像后仍然不行,这时候是代码本身的问题。
以下代码截取自GitHub:
https://github.com/tensorflow/models/issues/4203
Modify the code at line 145 in eval.py from:
metric_map = {
}metric_map[predictions_tag] = tf.metrics.mean_iou(predictions, labels, dataset.num_classes, weights=weights)
to:
metric_map = {
}# insert by trobrindices = tf.squeeze(tf.where(tf.less_equal(labels, dataset.num_classes - 1)), 1)labels = tf.cast(tf.gather(labels, indices), tf.int32)predictions = tf.gather(predictions, indices)# end of insertmetric_map[predictions_tag] = tf.metrics.mean_iou(predictions, labels, dataset.num_classes, weights=weights)
在中间插入该段后,评估可正常进行。
INFO:tensorflow:Starting evaluation at 2018-10-21-13:11:45
INFO:tensorflow:Evaluation [1/10]
INFO:tensorflow:Evaluation [2/10]
INFO:tensorflow:Evaluation [3/10]
INFO:tensorflow:Evaluation [4/10]
INFO:tensorflow:Evaluation [5/10]
INFO:tensorflow:Evaluation [6/10]
INFO:tensorflow:Evaluation [7/10]
INFO:tensorflow:Evaluation [8/10]
INFO:tensorflow:Evaluation [9/10]
INFO:tensorflow:Evaluation [10/10]
INFO:tensorflow:Finished evaluation at 2018-10-21-13:12:07
miou_1.0[0.594165504]