简体   繁体   English

如何处理语义分割中未知类的平均交集(mIOU)?

[英]How to handle the mean Intersection Over Union (mIOU) for unknown class in semantic segmentation?

I implemented a FCN network to do semantic segmentation.我实现了一个 FCN 网络来进行语义分割。 I am using Cityscapes as my dataset.我使用 Cityscapes 作为我的数据集。 As you know, there are some classes in Cityscapes that you ignore during the training and it is labeled as 255. I used weighted loss to ignore the loss for the unknown classes(set the loss to zero for unknown class).如您所知,Cityscapes 中有一些您在训练过程中忽略的类,它被标记为 255。我使用加权损失来忽略未知类的损失(将未知类的损失设置为零)。 Now I want to exclude unknown class from my evaluation metric(mean Intersection Over Union (mIOU)).It is not clear for me how to exclude the unknown class at this point.现在我想从我的评估指标中排除未知类(平均交叉联合(mIOU))。目前我不清楚如何排除未知类。

At the moment I am considering all the classes including the unknown class like this using tensorflow method:目前我正在考虑使用 tensorflow 方法的所有类,包括像这样的未知类:

 miou, confusion_mat = tf.metrics.mean_iou(labels=annotation, predictions=pred_annotation, num_classes=num_cls)

with tf.control_dependencies([tf.identity(confusion_mat)]):
    miou = tf.identity(miou)

I tried this , but it give an error for unbound label(for the unkonwn label)我试过这个,但它给出了未绑定标签的错误(对于未知标签)

miou, confusion_mat = tf.metrics.mean_iou(labels=annotation, predictions=pred_annotation, num_classes=(num_cls-1))

If you have a class that you want to ignore during the mIoU calculation, and you have access to the confusion matrix then you can do it like this:如果您想在 mIoU 计算期间忽略一个类,并且您可以访问混淆矩阵,那么您可以这样做:

  1. ignore the miou calculated by tensorflow (since it considers all classes and that is not what you want)忽略miou计算的 miou(因为它考虑了所有类,这不是你想要的)
  2. remove row and column from the confusion matrix that correspond to the class you want to ignore从混淆矩阵中删除与您要忽略的类对应的行和列
  3. recalculate miou metric with the new confusion matrix使用新的混淆矩阵重新计算miou度量

How to recalculate miou metric from the confusion matrix?如何从混淆矩阵重新计算miou度量?

  • iou for the first class: iou_0 = conf_mat[0,0] / (sum(conf_mat[0,:]) + sum(conf_mat[:,0]) - conf_mat[0,0])第一类的 iou: iou_0 = conf_mat[0,0] / (sum(conf_mat[0,:]) + sum(conf_mat[:,0]) - conf_mat[0,0])
  • iou for the second class: iou_1 = conf_mat[1,1] / (sum(conf_mat[1,:]) + sum(conf_mat[:,1]) - conf_mat[1,1])第二类的iou: iou_1 = conf_mat[1,1] / (sum(conf_mat[1,:]) + sum(conf_mat[:,1]) - conf_mat[1,1])
  • ... ...
  • in general for the class j : iou_j = conf_matrix[j,j] / (sum(conf_mat[j,:]) + sum(conf_mat[:,j]) - conf_mat[j,j])一般对于j类: iou_j = conf_matrix[j,j] / (sum(conf_mat[j,:]) + sum(conf_mat[:,j]) - conf_mat[j,j])

At the end, sum and average all these per class iou to get miou .最后,对每类iou所有这些求和求平均值,得到miou

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM