-
Notifications
You must be signed in to change notification settings - Fork 1.5k
SurfaceDistanceMetric (SDM) and HausdorffDistanceMetric (HDM) print wrong all-zero warning messages #2627
Copy link
Copy link
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request