Skip to content

Focal re-weighing instability #1

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
jeroendecloet opened this issue May 11, 2023 · 0 comments
Open

Focal re-weighing instability #1

jeroendecloet opened this issue May 11, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jeroendecloet
Copy link

Describe the bug
There is an edge case where the focal re-weighing scheme can produce numerically unstable derivatives. It is defined as:
$$u(p) = -\alpha (1 - p) ^ \gamma \log(p)$$
The derivative w.r.t $p$ is:
$$\frac{\partial u}{\partial p} = \alpha\gamma(1-p)^{\gamma-1}\log(p) -\alpha (1 - p) ^ \gamma \frac{\partial }{\partial p}\log(p)$$

Since $\gamma-1 \leq 0$, the derivative is not defined for $1-p=0$. This occurred to me during training of a model, resulting is NaNs in the model weights.

I fixed it by adding a small value to the focal re-weighing implementation (line 43 in ece_loss\loss.py):
self.alpha * ((1.0 - loss_p + 1e-10) ** self.gamma) * loss

@jeroendecloet jeroendecloet added the bug Something isn't working label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant