Skip to content

Commit

Permalink
added small eps to dice and iou to avoid NaN (#2545)
Browse files Browse the repository at this point in the history
bernardomig authored Jul 9, 2020

Unverified

This user has not yet uploaded their public signing key.
1 parent ee6f618 commit 9a367a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pytorch_lightning/metrics/functional/classification.py
Original file line number Diff line number Diff line change
@@ -908,7 +908,7 @@ def dice_score(

tp, fp, tn, fn, sup = stat_scores(pred=pred, target=target, class_index=i)

denom = (2 * tp + fp + fn).to(torch.float)
denom = (2 * tp + fp + fn + 1e-15).to(torch.float)

if torch.isclose(denom, torch.zeros_like(denom)).any():
# nan result
@@ -963,5 +963,5 @@ def iou(
tps = tps[1:]
fps = fps[1:]
fns = fns[1:]
iou = tps / (fps + fns + tps)
iou = tps / (fps + fns + tps + 1e-15)
return reduce(iou, reduction=reduction)

0 comments on commit 9a367a8

Please sign in to comment.