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

No problems with all losses, except JaccardLoss #884

Open
JonasZaoui opened this issue Jun 5, 2024 · 8 comments
Open

No problems with all losses, except JaccardLoss #884

JonasZaoui opened this issue Jun 5, 2024 · 8 comments

Comments

@JonasZaoui
Copy link

JonasZaoui commented Jun 5, 2024

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.

@qubvel
Copy link
Collaborator

qubvel commented Jun 5, 2024

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

@JonasZaoui
Copy link
Author

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...

@qubvel
Copy link
Collaborator

qubvel commented Jun 6, 2024

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!

@JonasZaoui
Copy link
Author

Of course! Thank you for your time.

@JonasZaoui
Copy link
Author

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

@qubvel
Copy link
Collaborator

qubvel commented Jun 8, 2024

That might help! Or you can consider weights for classes

@JonasZaoui
Copy link
Author

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 :)

@qubvel
Copy link
Collaborator

qubvel commented Jun 8, 2024

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

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