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

Multi label class loss plateau at epochs of 10 by the value of ~80 #25

Open
let-me-cook opened this issue Nov 12, 2020 · 4 comments
Open

Comments

@let-me-cook
Copy link

let-me-cook commented Nov 12, 2020

Trained on the bloodcell dataset, multi label class loss plateau at epoch of 10 by the value of ~80 and is still ~80 at epoch of 50, but the other loss (xywh and objectiveness loss) are able to reach near <1 value. However, by modifying the code in the class loss function such as

...
self.focal_loss = tfa.losses.SigmoidFocalCrossEntropy()
loss_class_arg = self.focal_loss(p_c_true, p_c_pred)
loss_class_arg = tf.clip_by_value(loss_class_arg, 0, 1000) # Prevent loss explosion

indicator_class = y_true[..., 4] * self.lambda_class
loss_class = K.sum(loss_class_arg * indicator_class)
return loss_class
...

The class loss value are able to reach ~30 at the epoch of ~30. Even though it may not look like a problem, as the bounding boxes prediction and the objectivity are correct, the class prediction arent able to distinguish between white blood cell and red blood cell.

@let-me-cook
Copy link
Author

I have found the solution,

p_c_true = K.one_hot(K.argmax(y_true[..., 5:], axis=-1), 1)

the code above shouldve been

p_c_true = K.one_hot(K.argmax(y_true[..., 5:], axis=-1), self.nb_class)

where self.nb_class presents number of class in the model.

@rodrigo2019
Copy link
Owner

Thank you for sharing and sorry for the late response.
Could you open a PR for it?

@let-me-cook
Copy link
Author

But before that, do you think there is another way of getting self.nb_class without having to modify __init__ so that when __init__ is called it doesnt have to be provided?

@rodrigo2019
Copy link
Owner

we can take from y_pred or y_true, the shape of them are: (SAMPLES, GRID SIZE H, GRID SIZE W, BOXES, 4 + 1 + CLASSES)
so probably something like that should work:
num_classes = y_pred.shape[-1] - 4 - 1

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

2 participants