Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.93k stars 1.09k forks source link

In MONAI's focal loss implementation, why does the alpha parameter become invalid when softmax is used and include_background=False? #8117

Open dancingreindeer opened 2 months ago

dancingreindeer commented 2 months ago

Discussed in https://github.com/Project-MONAI/MONAI/discussions/8116

Originally posted by **dancingreindeer** September 26, 2024 ```python if self.use_softmax: if not self.include_background and self.alpha is not None: self.alpha = None warnings.warn("include_background=False, alpha ignored when using softmax.") loss = softmax_focal_loss(input, target, self.gamma, self.alpha) ``` This is the code piece. Not sure why when we don't include background and when using softmax, alpha became invalid? Does this assume there are no label imbalance? How to address this when there is significantly more negative samples than positive samples in the experiment then?