mlyg / unified-focal-loss

Apache License 2.0
150 stars 22 forks source link

Question about asymmetric Focal Tversky term #12

Closed eugene87222 closed 2 years ago

eugene87222 commented 2 years ago

Hi,

I am curious about the implementation of asymmetric Focal Tversky loss. According to the paper, delta controls the weight of false positive term, but delta at line 311 is for false negative term.

mlyg commented 2 years ago

Hi Eugene,

Thanks for your question. The parameter delta controls the weights of both the false positive and false negative term, which replaces the alpha and beta parameters in the original Tversky loss. In the equation you have shown, you can see delta attaches itself to the p0ig1i term. For the ith pixel, p0 refers to the model predicting the pixel as background, despite the ground truth pixel being a foreground pixel (g1); i.e. this is a false negative. The (1 - delta) term p1ig0i is the false positive term - which corresponds to the code you have shown.

TLDR: the p0ig1i term in the equation is the false negative term, which is the same as the code. Delta controls both the false positive and negatives (as the false positive weighting is determined by 1-delta).

eugene87222 commented 2 years ago

Hi mlyg,

Thanks for your reply. But according to the definition of Tversky Index, the p0ig0i in the numerator part represents true positive. It seems like p0i and g0i both refer to the foreground class. Shouldn't the p0ig1i be false positive case?

mlyg commented 2 years ago

Sorry, you are right. According to the equation, p0ig1i is the false positive case.

The equation in the paper should have the delta(p1ig0i) and (1-delta)(p0ig1i). Thank you for pointing this out!

The code is correct, as I intended delta to track the beta parameter (penalising false negatives) in Tversky loss. However, as mentioned before, the delta term weights the relative contributions of false positives and negatives, and so it will affect both in either case.

eugene87222 commented 2 years ago

Thanks for your clarification!