Skip to content

Conversation

MrPrajwalB
Copy link
Contributor

@MrPrajwalB MrPrajwalB commented Oct 9, 2024

The current implementation is same as the one given in original paper . Although, it doesn't work as intended when value of reduced threshold is not 0.5. As per the paper, the focal term should be 1 when pt is less than reduced threshold and then exponentially decrease from 1 to 0 as pt goes from reduced threshold to 1. By this logic, the value of focal term should be 1 at pt equal to reduced threshold from both sides of the curve. From RHS the value is given as (1-pt/thresh) to power gamma multiplied by log pt. This will only be 1 at pt=thresh, when thresh=0.5, otherwise not.

So the correct formula focal term for pt>thresh should be ((1-pt)/(1-thresh) to the power gamma multiplied by log pt.

The corrected implementation goes hand in hand with the one done for softmax_focal_loss_with_logits which works as intended in the paper.

Fixed Binary focal loss when reduced threshold is not None. Focal term should be continuous and equal to 1 at pt equal to reduced threshold
@BloodAxe
Copy link
Owner

Hmmm, indeed!

Thanks for spotting this bug. I've never get any decent results with reduced focal loss, and this may explain why :)

focal_term

@BloodAxe BloodAxe merged commit 61ad685 into BloodAxe:develop Oct 11, 2024
0 of 16 checks passed
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.

2 participants