Skip to content

SurfaceDistanceMetric (SDM) and HausdorffDistanceMetric (HDM) print wrong all-zero warning messages #2627

@seannz

Description

@seannz

Describe the bug
SDM and HDM incorrectly warn that both prediction and ground truth are all 0 (for some class) even when only one of them is all 0 (for some class):

To Reproduce
Steps to reproduce the behavior (for HDM):

import torch
import monai
metric = monai.metrics.HausdorffDistanceMetric()
#forward direction
metric(torch.cat((torch.ones(1,1,256,256),torch.zeros(1,1,256,256)), dim=1), torch.randint(0,2,(1,2,256,256)))

/autofs/space/vault_021/users/siy0/anaconda3/lib/python3.8/site-packages/monai/metrics/utils.py:199: UserWarning: prediction is all 0, this may result in nan/inf distance.
  warnings.warn("prediction is all 0, this may result in nan/inf distance.")
/autofs/space/vault_021/users/siy0/anaconda3/lib/python3.8/site-packages/monai/metrics/utils.py:195: UserWarning: ground truth is all 0, this may result in nan/inf distance.
  warnings.warn("ground truth is all 0, this may result in nan/inf distance.")

#backward direction
metric(torch.randint(0,2,(1,2,256,256)),torch.cat((torch.ones(1,1,256,256),torch.zeros(1,1,256,256)), dim=1))

/autofs/space/vault_021/users/siy0/anaconda3/lib/python3.8/site-packages/monai/metrics/utils.py:195: UserWarning: ground truth is all 0, this may result in nan/inf distance.
  warnings.warn("ground truth is all 0, this may result in nan/inf distance.")
/autofs/space/vault_021/users/siy0/anaconda3/lib/python3.8/site-packages/monai/metrics/utils.py:199: UserWarning: prediction is all 0, this may result in nan/inf distance.
  warnings.warn("prediction is all 0, this may result in nan/inf distance.")

The same bug is there if SDM is run with symmetric=True

Expected behavior
Only the first warning should be displayed in each of the two above cases.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions