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

Error during argument validation: predictions can not contain ignore_index #2425

Closed
marianne-omnius opened this issue Mar 5, 2024 · 1 comment · Fixed by #2427
Closed
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.3.x

Comments

@marianne-omnius
Copy link

🐛 Bug

The validation of input arguments raises a RunTimeError if ignore_index appears in predictions.

To Reproduce

import torch
from torchmetrics.classification import MulticlassF1Score

metric = MulticlassF1Score(num_classes=3, ignore_index=-1)
preds = torch.tensor([0, 1, 2, -1])
target = torch.tensor([0, 1, 2, -1])
metric.update(preds, target)

Output:

RuntimeError: Detected more unique values in preds than num_classes. Expected only 3 but found 4 in preds.

Expected behavior

I would expect that the validation does not complain about ignore_index in predictions - at least when it's only in places where target also has ignore_index. The computation of the metric is already correct in this case.

Environment

  • TorchMetrics version: 1.3.0.post0 (pip installed)
  • Python & PyTorch Version: 3.10 & 2.2.0
  • Any other relevant information such as OS: Ubuntu

Workarounds

  • set validate_args=False when initializing the metric
  • replace ignore_index with 0 in preds
@marianne-omnius marianne-omnius added bug / fix Something isn't working help wanted Extra attention is needed labels Mar 5, 2024
Copy link

github-actions bot commented Mar 5, 2024

Hi! thanks for your contribution!, great first issue!

@Borda Borda changed the title Error during argument validation: predictions can not contain ignore_index Error during argument validation: predictions can not contain ignore_index Mar 5, 2024
@Borda Borda added the v1.3.x label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants