From d4cfc24f4228b39dffa8b1e863a0a69bb753e94b Mon Sep 17 00:00:00 2001 From: Chanuth412-pixel Date: Thu, 12 Nov 2026 18:45:02 +0530 Subject: [PATCH 1/4] docs: add missing loss classes to API reference Signed-off-by: Chanuth412-pixel --- docs/source/losses.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/source/losses.rst b/docs/source/losses.rst index 1dca79a1aca..b8e1e5e1ea7 100644 --- a/docs/source/losses.rst +++ b/docs/source/losses.rst @@ -73,6 +73,11 @@ Segmentation Losses .. autoclass:: FocalLoss :members: +`AsymmetricUnifiedFocalLoss` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: AsymmetricUnifiedFocalLoss + :members: + `TverskyLoss` ~~~~~~~~~~~~~ .. autoclass:: TverskyLoss @@ -98,6 +103,11 @@ Segmentation Losses .. autoclass:: HausdorffDTLoss :members: +`LogHausdorffDTLoss` +~~~~~~~~~~~~~~~~~~~~ +.. autoclass:: LogHausdorffDTLoss + :members: + `SoftclDiceLoss` ~~~~~~~~~~~~~~~~ .. autoclass:: SoftclDiceLoss @@ -118,6 +128,23 @@ Segmentation Losses .. autoclass:: MCCLoss :members: +Classification Losses +--------------------- + +`AUCMLoss` +~~~~~~~~~~ +.. autoclass:: AUCMLoss + :members: + + +Detection Losses +---------------- + +`BoxGIoULoss` +~~~~~~~~~~~~~ +.. autoclass:: BoxGIoULoss + :members: + Registration Losses ------------------- From 544eac7ecf6271582cdf0c9c97e03a64f061b433 Mon Sep 17 00:00:00 2001 From: Chanuth412-pixel Date: Thu, 12 Nov 2026 19:28:43 +0530 Subject: [PATCH 2/4] docs: correct AsymmetricUnifiedFocalLoss input description Signed-off-by: Chanuth412-pixel --- monai/losses/unified_focal_loss.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index 34fff9221ad..800fafc08f4 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -234,16 +234,16 @@ def forward(self, y_pred: torch.Tensor, y_true: torch.Tensor) -> torch.Tensor: Args: y_pred : the shape should be BNH[WD], where N is the number of classes. It only supports binary segmentation. - The input should be the original logits since it will be transformed by - a sigmoid in the forward function. + The input should contain probability values in the range [0, 1], + not raw logits. The forward function does not apply a sigmoid. y_true : the shape should be BNH[WD], where N is the number of classes. It only supports binary segmentation. Raises: - ValueError: When input and target are different shape - ValueError: When len(y_pred.shape) != 4 and len(y_pred.shape) != 5 - ValueError: When num_classes - ValueError: When the number of classes entered does not match the expected number + ValueError: If the input and target have incompatible shapes. + ValueError: If the input has neither 4 nor 5 dimensions. + ValueError: If the maximum target class index exceeds num_classes - 1 when ignore_index is None. + ValueError: If an unsupported reduction method is specified. """ if len(y_pred.shape) != 4 and len(y_pred.shape) != 5: raise ValueError(f"input shape must be 4 or 5, but got {y_pred.shape}") From 7d42cca7ef89f220fa23a6896d49fed2f7a33ffd Mon Sep 17 00:00:00 2001 From: Chanuth412-pixel Date: Thu, 12 Nov 2026 20:03:10 +0530 Subject: [PATCH 3/4] docs: improve AsymmetricUnifiedFocalLoss documentation Signed-off-by: Chanuth412-pixel --- monai/losses/unified_focal_loss.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index 800fafc08f4..7673ca8dda6 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -236,13 +236,31 @@ def forward(self, y_pred: torch.Tensor, y_true: torch.Tensor) -> torch.Tensor: It only supports binary segmentation. The input should contain probability values in the range [0, 1], not raw logits. The forward function does not apply a sigmoid. + y_true : the shape should be BNH[WD], where N is the number of classes. It only supports binary segmentation. + For single-channel predictions, y_true should also be + single-channel; both are expanded to two channels internally. + For two-channel predictions, when to_onehot_y=True, + y_true must contain single-channel class labels, which are + converted to one-hot format internally. + When to_onehot_y=False, y_true must have the same shape + as y_pred. + + Returns: + torch.Tensor: A scalar loss value calculated by combining + the Asymmetric Focal Loss and Asymmetric Focal Tversky Loss. Raises: ValueError: If the input and target have incompatible shapes. ValueError: If the input has neither 4 nor 5 dimensions. - ValueError: If the maximum target class index exceeds num_classes - 1 when ignore_index is None. + AssertionError: If one-hot conversion is enabled with a + two-channel prediction and the target is not single-channel. + RuntimeError: If one-hot conversion is attempted with a + target class index outside the valid range. + ValueError: If the maximum target class index exceeds + num_classes - 1 when ignore_index is None and one-hot + conversion is not applied. ValueError: If an unsupported reduction method is specified. """ if len(y_pred.shape) != 4 and len(y_pred.shape) != 5: From 6a6178b8fad9490ae694d4787ca6a5f3b961bc77 Mon Sep 17 00:00:00 2001 From: Chanuth412-pixel Date: Wed, 18 Nov 2026 15:24:16 +0530 Subject: [PATCH 4/4] docs: fix AsymmetricUnifiedFocalLoss docstring formatting Signed-off-by: Chanuth412-pixel --- monai/losses/unified_focal_loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index 7673ca8dda6..739c172e4a7 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -186,7 +186,7 @@ class AsymmetricUnifiedFocalLoss(_Loss): Reimplementation of the Asymmetric Unified Focal Tversky Loss described in: - "Unified Focal Loss: Generalising Dice and Cross Entropy-based Losses to Handle Class Imbalanced Medical Image Segmentation", - Michael Yeung, Computerized Medical Imaging and Graphics + Michael Yeung, Computerized Medical Imaging and Graphics """ def __init__(