Open jaanli opened 8 months ago
I ran into this issue as well. The point is that if macro-averaged MulticlassRecall
doesn't recieve one prediction for each class the runtime error you posted is thrown when compute()
is called.
The same example as you posted with one added example predicting the final class computes without error:
metric = MulticlassRecall(num_classes=5, average="macro")
input = torch.tensor([
[0.9, 0.1, 0, 0, 0],
[0.1, 0.2, 0.4, 0.3, 0],
[0, 1.0, 0, 0, 0],
[0, 0, 0.2, 0.8, 0],
[0, 0, 0, 0, 1.0]
])
target = torch.tensor([0, 1, 2, 3, 4])
metric.update(input, target)
metric.compute()
tensor(0.6000)
After looking around this is a duplicate of #150 and should be addressed by the still opened PR #166.
π Describe the bug
The example from the docs leads to a bug when modified slightly: https://pytorch.org/torcheval/stable/generated/torcheval.metrics.MulticlassRecall.html#torcheval.metrics.MulticlassRecall
Adding an extra class and specifying a "macro" average leads to a bug:
Yields:
Versions