From 618074b3406931a1828312e62e7c49ceea434b2e Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Thu, 15 Jan 2026 16:48:48 +0800 Subject: [PATCH 1/3] Update the docstrings to match the actual code defaults Signed-off-by: ytl0623 --- monai/losses/unified_focal_loss.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index 06704c0104..b58b406a7e 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -108,7 +108,7 @@ def __init__( Args: to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False. delta : weight of the background. Defaults to 0.7. - gamma : value of the exponent gamma in the definition of the Focal loss . Defaults to 0.75. + gamma : value of the exponent gamma in the definition of the Focal loss . Defaults to 2. epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. """ super().__init__(reduction=LossReduction(reduction).value) @@ -168,9 +168,8 @@ def __init__( to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False. num_classes : number of classes, it only supports 2 now. Defaults to 2. delta : weight of the background. Defaults to 0.7. - gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.75. - epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. - weight : weight for each loss function, if it's none it's 0.5. Defaults to None. + gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.5. + weight : weight for each loss function. Defaults to 0.5. Example: >>> import torch From 8b6c29425575b0deeeb9017d1bb437d37d533f19 Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Mon, 19 Jan 2026 10:02:51 +0800 Subject: [PATCH 2/3] minor fixes Signed-off-by: ytl0623 --- monai/losses/unified_focal_loss.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index b58b406a7e..b7ceafd5c3 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -44,7 +44,7 @@ def __init__( Args: to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. delta : weight of the background. Defaults to 0.7. - gamma : value of the exponent gamma in the definition of the Focal loss . Defaults to 0.75. + gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.75. epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. """ super().__init__(reduction=LossReduction(reduction).value) @@ -108,7 +108,7 @@ def __init__( Args: to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False. delta : weight of the background. Defaults to 0.7. - gamma : value of the exponent gamma in the definition of the Focal loss . Defaults to 2. + gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 2. epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. """ super().__init__(reduction=LossReduction(reduction).value) @@ -158,9 +158,9 @@ def __init__( self, to_onehot_y: bool = False, num_classes: int = 2, - weight: float = 0.5, - gamma: float = 0.5, delta: float = 0.7, + gamma: float = 0.5, + weight: float = 0.5, reduction: LossReduction | str = LossReduction.MEAN, ): """ From 64bc876e55d642217ec81873bd80468a1c874dd6 Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Mon, 23 Feb 2026 09:07:52 +0800 Subject: [PATCH 3/3] reorder docstring args to match declaration Signed-off-by: ytl0623 --- monai/losses/unified_focal_loss.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/monai/losses/unified_focal_loss.py b/monai/losses/unified_focal_loss.py index b7ceafd5c3..745513fec0 100644 --- a/monai/losses/unified_focal_loss.py +++ b/monai/losses/unified_focal_loss.py @@ -45,7 +45,7 @@ def __init__( to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. delta : weight of the background. Defaults to 0.7. gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.75. - epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. + epsilon : it defines a very small number each time. similarly smooth value. Defaults to 1e-7. """ super().__init__(reduction=LossReduction(reduction).value) self.to_onehot_y = to_onehot_y @@ -109,7 +109,7 @@ def __init__( to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False. delta : weight of the background. Defaults to 0.7. gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 2. - epsilon : it defines a very small number each time. simmily smooth value. Defaults to 1e-7. + epsilon : it defines a very small number each time. similarly smooth value. Defaults to 1e-7. """ super().__init__(reduction=LossReduction(reduction).value) self.to_onehot_y = to_onehot_y @@ -158,18 +158,20 @@ def __init__( self, to_onehot_y: bool = False, num_classes: int = 2, - delta: float = 0.7, - gamma: float = 0.5, weight: float = 0.5, + gamma: float = 0.5, + delta: float = 0.7, reduction: LossReduction | str = LossReduction.MEAN, ): """ Args: to_onehot_y : whether to convert `y` into the one-hot format. Defaults to False. num_classes : number of classes, it only supports 2 now. Defaults to 2. - delta : weight of the background. Defaults to 0.7. - gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.5. weight : weight for each loss function. Defaults to 0.5. + gamma : value of the exponent gamma in the definition of the Focal loss. Defaults to 0.5. + delta : weight of the background. Defaults to 0.7. + + Example: >>> import torch