We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There is a bug that happens with metrics that returns dictionaries when used in MetricCollection.
Steps to reproduce the behavior...
import torch from torchmetrics import Metric, MetricCollection class CustomAccuracy(Metric): def __init__(self): super().__init__() self.prefix = 'accuracy' def update(self, preds: torch.Tensor, target: torch.Tensor) -> None: self.correct = torch.sum(preds == target) self.total = preds.numel() def compute(self) -> torch.Tensor: res = self.correct.float() / self.total return {f"{self.prefix}/value": res} class CustomPrecision(Metric): def __init__(self): super().__init__() self.prefix = 'precision' def update(self, preds: torch.Tensor, target: torch.Tensor) -> None: self.true_positives = torch.sum((preds == target) & (preds == 1)) self.predicted_positives = torch.sum(preds == 1) def compute(self) -> torch.Tensor: res = self.true_positives.float() / self.predicted_positives return {f"{self.prefix}/value": res} # Initialize MetricCollection with Accuracy and Precision metrics = MetricCollection([CustomAccuracy(), CustomPrecision()]) # Mock predictions and targets preds = torch.tensor([1, 0, 0, 1]) targets = torch.tensor([1, 0, 0, 0]) # Update metrics with current batch metrics(preds, targets) # Print the calculated metrics print(metrics.compute()) # Returns {'precisionaccuracy/value': tensor(0.7500), 'precisionprecision/value': tensor(0.5000)}
I expect the results to be
{'accuracy/value': tensor(0.7500), 'precision/value': tensor(0.5000)}
and not
{'precisionaccuracy/value': tensor(0.7500), 'precisionprecision/value': tensor(0.5000)}
conda
pip
Please note that this works correctly in torchmetrics 0.11.4
The text was updated successfully, but these errors were encountered:
Hi! thanks for your contribution!, great first issue!
Sorry, something went wrong.
SkafteNicki
Successfully merging a pull request may close this issue.
🐛 Bug
There is a bug that happens with metrics that returns dictionaries when used in MetricCollection.
To Reproduce
Steps to reproduce the behavior...
Code sample
Expected behavior
I expect the results to be
{'accuracy/value': tensor(0.7500), 'precision/value': tensor(0.5000)}
and not
{'precisionaccuracy/value': tensor(0.7500), 'precisionprecision/value': tensor(0.5000)}
Environment
conda
,pip
, build from source): 1.1.1, via pipAdditional context
Please note that this works correctly in torchmetrics 0.11.4
The text was updated successfully, but these errors were encountered: