qubvel-org/segmentation_models.pytorch

No problems with all losses, except JaccardLoss

JonasZaoui opened this issue · 8 comments

Hi !
A quick question about a loss, I've used quite a few losses and loss mixtures without any problems, but when I use iou loss, I only get empty predictions. My ground truth is a multiclass mask, without encoding labels on channels

loss = smp.losses.JaccardLoss(mode='multiclass', from_logits=True)

However, with the other losses, I'm fine with multiclasses, and with logits too.

Hi @JonasZaoui, thanks for the issue!
Can you please provide example of tensors you are passing to the loss? Or at least it's statistics (min, max, unique) + shape

Hi @qubvel, thanks for your answer.
Of course, here :

unique pred [-17.930422 -17.655249 -17.478573 ...  12.213453  12.355886  12.49832 ]
min pred -17.930422
max pred 12.49832
max pred (2, 3, 800, 800)

unique target [0 1 2]
min target 0
max target 2
max target (2, 1, 800, 800)

My hypothesis is that the model optimises itself on the very majority class, the background, and predicts 0 all the time.

When I use class = [1,2] on the other hand, I get predictions for class 1 (but not for class 2). So it's weird...

Ok, thanks, I quickly checked the code but did not find any obvious issue. I will try to investigate it further.. Just in case you identify the issue, please let me know!

Of course! Thank you for your time.

Do you think that's if i ignore background in iou computation, it can fix the problem ? (Or increase performance for imbalanced binary segmentation)

That might help! Or you can consider weights for classes

I have only one class (0 for background, and 1 for the class). When i ignore the class 0, my dice loss is null. When i use weighted bce it's okay. Never mind the iou :)

If you have only a background and one class, your case can be considered as binary segmentation. There is an example notebook with dice loss for such a case.
https://github.com/qubvel/segmentation_models.pytorch/blob/master/examples/binary_segmentation_intro.ipynb