Skip to content

Commit

Permalink
Bug fix: recall macro average computation when not all classes are pr…
Browse files Browse the repository at this point in the history
…esent in target and input

Summary: Both f1 and precision are able to perform macro averaging when the input and target both do not contained instances of a class (e.g if num_classes = 5 and both input/target contain only instances of 4 classes). However, recall computation fails in such a case. This diff adds a missing line to make this case work.

Reviewed By: JKSenthil

Differential Revision: D62046138

fbshipit-source-id: 3d6706ed22b8143d61edf8b4891dec6f378b0723
  • Loading branch information
spurra authored and facebook-github-bot committed Aug 31, 2024
1 parent 7b99909 commit a88a579
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions torcheval/metrics/functional/classification/recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def _recall_compute(
# Ignore classes which have no samples in `target` and `input`
mask = (num_labels != 0) | (num_predictions != 0)
num_tp = num_tp[mask]
num_labels = num_labels[mask]

recall = num_tp / num_labels

Expand Down

0 comments on commit a88a579

Please sign in to comment.