MeanIoU ( when num class is 1 the function can't work )
Linaom1214 opened this issue · comments
Linaom1214 commented
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
yancong commented
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. ^_^