Skip to content
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

focal loss modulator #1

Open
bei-startdt opened this issue Feb 11, 2019 · 8 comments
Open

focal loss modulator #1

bei-startdt opened this issue Feb 11, 2019 · 8 comments
Assignees

Comments

@bei-startdt
Copy link

bei-startdt commented Feb 11, 2019

how to infer the modulator

the code in your repo

modulator = tf.exp(-gamma * labels * logits - gamma * tf.log1p(
          tf.exp(-1.0 * logits)))

for focal loss in tensorflow/models/blob/master/research/object_detection
the focal loss form is the same as what is shown in paper

    prediction_probabilities = tf.sigmoid(prediction_tensor)
    p_t = ((target_tensor * prediction_probabilities) +
           ((1 - target_tensor) * (1 - prediction_probabilities)))
    modulating_factor = 1.0
    if self._gamma:
      modulating_factor = tf.pow(1.0 - p_t, self._gamma)

Could you please tell me how to transform the paper form to your form?

Thank you very much!

@richardaecn
Copy link
Owner

richardaecn commented Feb 11, 2019

Hi @bei-startdt

Thanks for pointing this out! The implementation you mentioned is not very numerically stable (same for the implementation in https://github.com/tensorflow/tpu/blob/master/models/official/retinanet/retinanet_model.py#L130-L162). When gamma is small (< 1), there might be NaN occurs during back-propagation.

The full derivation can be found in the figure below. Hope this will help!
img_3584

@bei-startdt
Copy link
Author

Thanks a lot!

@richardaecn richardaecn self-assigned this Mar 5, 2019
@Angzz
Copy link

Angzz commented Apr 3, 2019

@richardaecn Hi,have you experiment on detection datasets such as coco, and the results?

@richardaecn
Copy link
Owner

Hi @Angzz , we haven't tried it on detection datasets.

@XCRobert
Copy link

@richardaecn Hi , have you compared the class balanced focal loss with the orignal focal loss using resnet 50 or 101 ? When did such comparsion , you used resnet 32 in your paper. Will stronger networks weaken the framework you proposed ?

@shawnthu
Copy link

shawnthu commented Oct 8, 2019

modulator = tf.exp(-gamma * labels * logits - gamma * tf.log1p( tf.exp(-1.0 * logits)))
should be
modulator = tf.exp(-gamma * labels * logits - gamma * tf.log1p( tf.exp(-1.0 * labels * logits)))
labels in {-1, 1}

@richardaecn
Copy link
Owner

Hi @shawnthu, in the formulation, we are using 1 for positive labels and 0 for negative labels.

@shawnthu
Copy link

shawnthu commented Oct 9, 2019

Hi @shawnthu, in the formulation, we are using 1 for positive labels and 0 for negative labels.

in fact we are both right, but your solution more concise (^o^)/~

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

No branches or pull requests

5 participants