Skip to content

Wrong generalized dice score metric when denominator is 0 but prediction is non-empty #4510

@jlcsilva

Description

@jlcsilva

Describe the bug
When the denominator of the generalized dice score metric is zero, i.e., the ground-truth is empty, score should be 1 if the prediction is also empty and 0 otherwise. Right now, the output score is always 1.

To Reproduce

>>> from monai.metrics import GeneralizedDiceScore, compute_generalized_dice
>>> import torch
>>> pred = torch.ones((1, 1, 3, 3))
>>> target = torch.zeros((1, 1, 3, 3))
>>> compute_generalized_dice(pred, target)
tensor([1.])

Expected behavior
Since the prediction is not empty, the score should be 0.

Environment

================================
Printing MONAI config...

MONAI version: 0.9.0+0.gaf0e0e9f.dirty
Numpy version: 1.22.3
Pytorch version: 1.11.0
MONAI flags: HAS_EXT = False, USE_COMPILED = False
MONAI rev id: af0e0e9
MONAI file: /home/joao/MONAI/monai/init.py

Optional dependencies:
Pytorch Ignite version: 0.4.8
Nibabel version: 3.2.2
scikit-image version: 0.19.2
Pillow version: 9.0.1
Tensorboard version: 2.9.0
gdown version: 4.4.0
TorchVision version: 0.12.0
tqdm version: 4.64.0
lmdb version: 1.3.0
psutil version: 5.9.1
pandas version: 1.4.2
einops version: 0.4.1
transformers version: 4.19.2
mlflow version: 1.26.1
pynrrd version: 0.4.3

For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

================================
Printing system config...

System: Linux
Linux version: Ubuntu 20.04.3 LTS
Platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Processor: x86_64
Machine: x86_64
Python version: 3.10.4
Process name: python
Command: ['python', '-c', 'import monai; monai.config.print_debug_info()']
Open files: []
Num physical CPUs: 6
Num logical CPUs: 6
Num usable CPUs: 6
CPU usage (%): [5.1, 3.6, 4.1, 3.6, 4.1, 100.0]
CPU freq. (MHz): 3600
Load avg. in last 1, 5, 15 mins (%): [0.8, 1.0, 1.3]
Disk usage (%): 20.6
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 11.7
Available memory (GB): 10.0
Used memory (GB): 1.4

================================
Printing GPU config...

Num GPUs: 1
Has CUDA: True
CUDA version: 11.3
cuDNN enabled: True
cuDNN version: 8200
Current device: 0
Library compiled for CUDA architectures: ['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_37']
GPU 0 Name: NVIDIA GeForce GTX 1060 3GB
GPU 0 Is integrated: False
GPU 0 Is multi GPU board: False
GPU 0 Multi processor count: 9
GPU 0 Total memory (GB): 3.0
GPU 0 CUDA capability (maj.min): 6.1

Additional context
I'm the author of the PR that introduced this metric, so the mistake is on me. Sorry guys! Will make a PR for a fix right away

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions