Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Linaom1214 opened this issue Nov 7, 2022 · 1 comment
Closed

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

Linaom1214 opened this issue Nov 7, 2022 · 1 comment

Comments

@Linaom1214
Copy link

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
@ice-tong
Copy link
Collaborator

ice-tong commented Nov 7, 2022

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. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants