Skip to content

Enhance DiceMetric to support counting negative samples #4160

@yiheng-wang-nv

Description

@yiheng-wang-nv

I think the DiceMetric may has an error when there is no foreground for y but has foreground for y_pred. According to the formula, the result should be 0, but so far the class will return nan:

torch.where(y_o > 0, (2.0 * intersection) / denominator, torch.tensor(float("nan"), device=y_o.device))

The earliest commit I can found is already use this way for calculation: see https://github.com/Project-MONAI/MONAI/pull/285/files#diff-df0f76defe29c2c91286e52334ead7a0f1f54e392d1a3e8280e2e714800dc4cbL96

I think we may need to use:

torch.where(denominator > 0, (2.0 * intersection) / denominator, torch.tensor(float("nan"), device=y_o.device))

In addition, we use a fixed value: nan to fill the cases that the ground truth (as I mentioned, may need to be placed by denominator) has no foreground. However, in some practical situations, people may consider to use other values such as 1 instead. For example, in
the latest Kaggle competition: https://www.kaggle.com/competitions/uw-madison-gi-tract-image-segmentation/overview/evaluation , it says:

where X is the predicted set of pixels and Y is the ground truth. The Dice coefficient is defined to be 1 when both X and Y are empty.

Therefore, I think we may need to add an argument here thus users can specify which value to use.

Hi @ristoh @Nic-Ma @wyli @ericspod , could you please help to double check it? Thanks!

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions