Skip to content

Explicitly set reduction for Focal loss #1165

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

simonreise
Copy link

@simonreise simonreise commented May 27, 2025

Focal loss have a reduction parameter, but it is not set as a self.reduction value.

This does not affect loss functionality, but it can be misleading, because by default __init__ function of _Loss sets self.reduction to "mean".

For example:

>>> loss = smp.losses.FocalLoss(..., reduction="none")
>>> loss.reduction
'mean'

This can make checks like this fail, while they should pass

if hasattr(loss, "reduction") and loss.reduction != "none":
    raise ValueError("basic loss must have reduction = none")

This is a purely cosmetical addition that should not affect anything but can improve user experience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant