Skip to content

Fix wrong accumulation with average='none' #1046

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

Merged
merged 13 commits into from
May 27, 2022
2 changes: 1 addition & 1 deletion torchmetrics/functional/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _accuracy_compute(
numerator = tp + tn
denominator = tp + tn + fp + fn
else:
numerator = tp
numerator = tp.clone()
denominator = tp + fn

if mdmc_average != MDMCAverageMethod.SAMPLEWISE:
Expand Down
4 changes: 2 additions & 2 deletions torchmetrics/functional/classification/precision_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _precision_compute(
tensor(0.2500)
"""

numerator = tp
numerator = tp.clone()
denominator = tp + fp

if average == AverageMethod.MACRO and mdmc_average != MDMCAverageMethod.SAMPLEWISE:
Expand Down Expand Up @@ -241,7 +241,7 @@ def _recall_compute(
>>> _recall_compute(tp, fp, fn, average='micro', mdmc_average=None)
tensor(0.2500)
"""
numerator = tp
numerator = tp.clone()
denominator = tp + fn

if average == AverageMethod.MACRO and mdmc_average != MDMCAverageMethod.SAMPLEWISE:
Expand Down
2 changes: 1 addition & 1 deletion torchmetrics/functional/classification/specificity.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _specificity_compute(
tensor(0.6250)
"""

numerator = tn
numerator = tn.clone()
denominator = tn + fp
if average == AverageMethod.NONE and mdmc_average != MDMCAverageMethod.SAMPLEWISE:
# a class is not present if there exists no TPs, no FPs, and no FNs
Expand Down