Skip to content
Open
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
4 changes: 4 additions & 0 deletions monai/losses/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def __init__(
lambda_dice: float = 1.0,
lambda_ce: float = 1.0,
label_smoothing: float = 0.0,
soft_label: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find test files and search for soft_label references
find . -type f -name "*test*dice*" -o -name "*dice*test*" | head -20
echo "---"
rg -n "soft_label" --type=py -g '*test*' | head -30

Repository: Project-MONAI/MONAI

Length of output: 1666


🏁 Script executed:

#!/bin/bash
# Check test_dice_ce_loss.py for soft_label coverage
echo "=== test_dice_ce_loss.py content ==="
wc -l ./tests/losses/test_dice_ce_loss.py
echo "---"
head -100 ./tests/losses/test_dice_ce_loss.py
echo "---"
rg -n "soft_label" ./tests/losses/test_dice_ce_loss.py

# Check monai/losses/dice.py around line 677
echo ""
echo "=== monai/losses/dice.py around line 677 ==="
sed -n '670,690p' ./monai/losses/dice.py

Repository: Project-MONAI/MONAI

Length of output: 5289


🏁 Script executed:

#!/bin/bash
# Check how soft_label is used in DiceCELoss
echo "=== Check DiceCELoss implementation of soft_label ==="
sed -n '600,750p' ./monai/losses/dice.py | grep -A 30 "class DiceCELoss"
echo ""
echo "=== Full __init__ and forward of DiceCELoss ==="
sed -n '600,800p' ./monai/losses/dice.py | tail -100

Repository: Project-MONAI/MONAI

Length of output: 6067


🏁 Script executed:

#!/bin/bash
# Let's verify that soft_label is actually being used in DiceLoss forward
echo "=== Check if soft_label is used in DiceLoss.forward ==="
rg -n "soft_label" ./monai/losses/dice.py | head -20

Repository: Project-MONAI/MONAI

Length of output: 822


🏁 Script executed:

#!/bin/bash
# Verify the test_dice_loss.py has soft_label tests
echo "=== test_dice_loss.py soft_label test cases ==="
sed -n '35,50p' ./tests/losses/test_dice_loss.py

Repository: Project-MONAI/MONAI

Length of output: 850


Add unit test for DiceCELoss with soft_label=True.

The soft_label parameter was added to DiceCELoss but test cases in test_dice_ce_loss.py do not cover this parameter. Add test cases with soft_label=True to ensure proper functionality, consistent with existing DiceLoss tests.

) -> None:
"""
Args:
Expand Down Expand Up @@ -715,6 +716,8 @@ def __init__(
label_smoothing: a value in [0, 1] range. If > 0, the labels are smoothed
by the given factor to reduce overfitting.
Defaults to 0.0.
soft_label: whether the target contains non-binary values (soft labels) or not.
If True a soft label formulation of the DiceLoss will be used.

"""
super().__init__()
Expand All @@ -737,6 +740,7 @@ def __init__(
smooth_dr=smooth_dr,
batch=batch,
weight=dice_weight,
soft_label=soft_label,
)
self.cross_entropy = nn.CrossEntropyLoss(weight=weight, reduction=reduction, label_smoothing=label_smoothing)
self.binary_cross_entropy = nn.BCEWithLogitsLoss(pos_weight=weight, reduction=reduction)
Expand Down
Loading