ranking icon indicating copy to clipboard operation
ranking copied to clipboard

[Feature Request] Circle loss implementation

Open levyfan opened this issue 5 years ago • 0 comments

Circle loss is recently proposed (https://arxiv.org/abs/2002.10857) for image recognition tasks (face recognition, person re-identification, and image retrieval).

The implementation could be summarized as:

for i, j in ...:
    alpha_i = tf.stop_gradient(tf.nn.relu(1 + m - score_i))
    alpha_j = tf.stop_gradient(tf.nn.relu(score_j + m))
    loss = alpha_j * (score_j - m) - alpha_i * (score_i - 1 + m)
    loss = tf.exp(loss * gamma)
return tf.math.log1p(tf.math.reduce_sum(losses))

and score should be in [0, 1].

As for lambda weight, the loss might be modified as tf.math.log1p(tf.math.reduce_sum(losses * loss_weights)).

levyfan avatar Mar 30 '20 08:03 levyfan