open-mmlab / mmeval

A unified evaluation library for multiple machine learning libraries

Home Page:https://mmeval.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MeanIoU ( when num class is 1 the function can't work )

Linaom1214 opened this issue · comments

Describe the bug
MeanIoU ( when num class is 1 the function can't work )

Reproduction

miou = MeanIoU(num_classes=1)
for i in range(10):
  labels = torch.randint(0, 2, size=(100, 10, 10))
  predicts = torch.randint(0, 2, size=(100, 10, 10))
  miou.add(predicts, labels)
miou.compute()  

Error traceback

[/usr/local/lib/python3.7/dist-packages/mmeval/metrics/mean_iou.py](https://localhost:8080/#) in compute_confusion_matrix(self, prediction, label, num_classes)
    204             num_classes * label + prediction, minlength=num_classes**2)
    205         confusion_matrix = confusion_matrix_1d.reshape(num_classes,
--> 206                                                        num_classes)
    207         return confusion_matrix.cpu().numpy()
    208 

RuntimeError: shape '[1, 1]' is invalid for input of size 3

Hi @Linaom1214 , thanks for your attention to MMEval!

Since the input range is [0, 1], we should set the num_classes of MeanIoU to 2.

For binary segmentation, the dim of the output channel is usually 1, but we cannot directly use the dim of output channel as the num_classes in MeanIoU.

A related PR in mmseg: open-mmlab/mmsegmentation#2016

Feel free to feedback if you have any problems. ^_^