class-balanced-loss icon indicating copy to clipboard operation
class-balanced-loss copied to clipboard

focal loss modulator

Open bei-startdt opened this issue 6 years ago • 8 comments

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!

bei-startdt avatar Feb 11 '19 06:02 bei-startdt

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

richardaecn avatar Feb 11 '19 07:02 richardaecn

Thanks a lot!

bei-startdt avatar Feb 11 '19 07:02 bei-startdt

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

Angzz avatar Apr 03 '19 12:04 Angzz

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

richardaecn avatar Apr 03 '19 13:04 richardaecn

@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 ?

XCRobert avatar Sep 23 '19 14:09 XCRobert

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}

shawnthu avatar Oct 08 '19 09:10 shawnthu

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

richardaecn avatar Oct 08 '19 16:10 richardaecn

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^)/~

shawnthu avatar Oct 09 '19 02:10 shawnthu