Skip to content

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

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!

Activity

  1. Rusheel86 commented on Feb 14, 2026

    @Rusheel86
    Contributor

    This seems like an interesting and valuable feature for medical imaging so I'd like to help implement ignore_index by introducing a binary masking step that excludes specified label values from the calculations.

  2. jermmy19998 commented on Feb 15, 2026

    @jermmy19998
    Author

    could merge with Ignore Class #8667

  3. added a commit that references this issue on Sep 9, 2026
    7af8653
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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