Skip to content

Feature Request: Support ignore_index / ignore_class in Losses and Metrics #8734

@jermmy19998

Description

@jermmy19998

In practical medical image segmentation, it is very common to have label values that should be ignored (e.g. padding, unlabeled regions, auxiliary classes).

Currently, MONAI losses and metrics (e.g. DiceLoss, DiceMetric, MeanIoU) do not natively support ignoring specific classes or label values. Users must manually mask predictions and targets, which is error-prone and inconsistent.

Request:
Add native support for an argument such as ignore_index or ignore_classes to losses and metrics.

Example:

DiceCELoss(include_background=False, ignore_index=2)
DiceMetric(include_background=False, ignore_index=2)

Expected behavior:

Voxels with ignored labels are excluded from numerator and denominator

Works consistently for binary and multi-class segmentation

Compatible with reduction="mean" and get_not_nans

This would improve correctness, reproducibility, and align MONAI with common PyTorch APIs (e.g. CrossEntropyLoss(ignore_index)).

Thanks for considering!

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