fudannlp16 / focal-loss

Tensorflow version implementation of focal loss for binary and multi classification
108 stars 27 forks source link

focal-loss: alpha parameter in binary classification #6

Open AlphaNext opened 5 years ago

AlphaNext commented 5 years ago

"alpha: A scalar for focal loss alpha hyper-parameter. If positive samples number > negtive samples number, alpha < 0.5 and vice versa." your function: L=-labels*(1-alpha)*((1-y_pred)*gamma)*tf.log(y_pred)-\ (1-labels)*alpha*(y_pred**gamma)*tf.log(1-y_pred) note: * and ** are same?

in original paper function: L = -labels*alpha*((1-y_pred)^gamma)*tf.log(y_pred)-\ (1-labels)*(1-alpha)*(y_pred^gamma)*tf.log(1-y_pred)

so i think if positive samples number > negtive , alpha > 0.5 and vice versa. However, in your ways, if positive > negtive, alpha < 0.5 and vice versa.

lilmangolil commented 5 years ago

您好,请问运用focal-loss的时候您出现过这个问题吗?InvalidArgumentError (see above for traceback): tags and values not the same shape: [] != [256]

AlphaNext commented 5 years ago

没遇到过 @lilmangolil , 你注意下公式里面tensor 如何做平方运算,最简单的就是直接相乘,或者用pow

chenzhutian commented 5 years ago

@lilmangolil 这个是因为你有把返回的loss放进这个函数吧tf.summary.scalar tf.summary.scalar要求输入为scalar,他的函数返回的loss是个tensor 你还需要reduce一下