Skip to content

Commit

Permalink
Fix MIoU metric when self.total_union==0 (#1558)
Browse files Browse the repository at this point in the history
* replace nan when total_union=0

* mask to avoid nans

* simplify

Co-authored-by: Mihir Patel <mihir.v.patel7@gmail.com>
Co-authored-by: Landan Seguin <landanjs@gmail.com>
  • Loading branch information
3 people authored Sep 26, 2022
1 parent 78b6607 commit 1378466
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion composer/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def update(self, logits: Tensor, targets: Tensor):

def compute(self):
"""Aggregate state across all processes and compute final metric."""
return 100 * (self.total_intersect / self.total_union).mean() #type: ignore (third-party)
total_intersect = self.total_intersect[self.total_union != 0] # type: ignore (third-party)
total_union = self.total_union[self.total_union != 0] # type: ignore (third-party)
return 100 * (total_intersect / total_union).mean()


class Dice(Metric):
Expand Down

0 comments on commit 1378466

Please sign in to comment.