Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label smoothing param in DiceCELoss #8000

Merged
merged 8 commits into from
Aug 9, 2024
Merged
Changes from 3 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
5 changes: 4 additions & 1 deletion monai/losses/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ def __init__(
weight: torch.Tensor | None = None,
lambda_dice: float = 1.0,
lambda_ce: float = 1.0,
label_smoothing: float = 0.0,
ytl0623 marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""
Args:
Expand Down Expand Up @@ -704,6 +705,8 @@ def __init__(
Defaults to 1.0.
lambda_ce: the trade-off weight value for cross entropy loss. The value should be no less than 0.0.
Defaults to 1.0.
label_smoothing (float): a value in [0, 1] range. If > 0, the labels are smoothed by the given factor to reduce overfitting.
Default is 0.0.

"""
super().__init__()
Expand All @@ -728,7 +731,7 @@ def __init__(
batch=batch,
weight=dice_weight,
)
self.cross_entropy = nn.CrossEntropyLoss(weight=weight, reduction=reduction)
self.cross_entropy = nn.CrossEntropyLoss(weight=weight, reduction=reduction, label_smoothing=label_smoothing)
self.binary_cross_entropy = nn.BCEWithLogitsLoss(pos_weight=weight, reduction=reduction)
if lambda_dice < 0.0:
raise ValueError("lambda_dice should be no less than 0.0.")
Expand Down
Loading