rodrigo2019/keras_yolo2

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

let-me-cook opened this issue · 4 comments

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.

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.

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

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?

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