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

F1-score loss for RRN #51

Open
MjdMahasneh opened this issue Apr 29, 2020 · 0 comments
Open

F1-score loss for RRN #51

MjdMahasneh opened this issue Apr 29, 2020 · 0 comments

Comments

@MjdMahasneh
Copy link

MjdMahasneh commented Apr 29, 2020

I am trying to implement F1-score loss for the RPN's classification head, but the loss is stuck at ~0.9993782699 during training. here is my implementation:

def rpn_loss_cls_F_one(num_anchors):
        def rpn_loss_cls(y_true, y_pred):
                if K.image_dim_ordering() == 'tf':                        

                        tp = K.sum(K.cast( y_true[:, :, :, :num_anchors] * y_pred[:, :, :, :], 'float'), axis=0)
                        fp = K.sum(K.cast((1-y_true[:, :, :, :num_anchors])* y_pred[:, :, :, :], 'float'), axis=0)
                        fn = K.sum(K.cast(y_true[:, :, :, :num_anchors]*(1- y_pred[:, :, :, :]), 'float'), axis=0)

                        p = (tp / (tp + fp + K.epsilon()))
                        r = (tp / (tp + fn + K.epsilon())) 

                        f1 = 2*p*r / (p+r+K.epsilon())
                        f1 = tf.where(tf.is_nan(f1), tf.zeros_like(f1), f1)
                        return 1 - K.mean(f1)


        return rpn_loss_cls

Is my implementation correct? if so, what possible reasons can I further look into to explain this strange loss behaviour during the training?

Thanks :)

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

1 participant