Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/source/losses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Segmentation Losses
.. autoclass:: FocalLoss
:members:

`AsymmetricUnifiedFocalLoss`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: AsymmetricUnifiedFocalLoss
:members:

`TverskyLoss`
~~~~~~~~~~~~~
.. autoclass:: TverskyLoss
Expand All @@ -98,6 +103,11 @@ Segmentation Losses
.. autoclass:: HausdorffDTLoss
:members:

`LogHausdorffDTLoss`
~~~~~~~~~~~~~~~~~~~~
.. autoclass:: LogHausdorffDTLoss
:members:

`SoftclDiceLoss`
~~~~~~~~~~~~~~~~
.. autoclass:: SoftclDiceLoss
Expand All @@ -118,6 +128,23 @@ Segmentation Losses
.. autoclass:: MCCLoss
:members:

Classification Losses
---------------------

`AUCMLoss`
~~~~~~~~~~
.. autoclass:: AUCMLoss
:members:


Detection Losses
----------------

`BoxGIoULoss`
~~~~~~~~~~~~~
.. autoclass:: BoxGIoULoss
:members:

Registration Losses
-------------------

Expand Down
32 changes: 25 additions & 7 deletions monai/losses/unified_focal_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -234,16 +234,34 @@ 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.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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: 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.
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.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"""
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}")
Expand Down