bermanmaxim / LovaszSoftmax

Code for the Lovász-Softmax loss (CVPR 2018)
http://bmax.im/LovaszSoftmax
MIT License
1.38k stars 269 forks source link

Lovasz softmax with 1 class and small batch does not learn #26

Closed JohnMBrandt closed 5 years ago

JohnMBrandt commented 5 years ago

I have an image segmentation task with small batch size (4-8) and some samples that have only the background (negative) class.

I have implemented lovasz softmax as below:

loss2 = lovasz_softmax(probs, labels, classes=[1], per_image=False)

where probs are B, H, W, C, and label is B, H, W with a range of [0, 1]

However, the network does not learn at all -- the output feature maps look random, and tuning the learning rate does not improve the issue.

The same network works fine with dice, Tversky, focal, or BCE loss.

I think it is due to the presence of background-only classes -- I know that classes = 'present' solves this for multi class problems. Is there a way to do the same for a binary lovasz softmax?

JohnMBrandt commented 5 years ago

Specifically -- the predictions converge to 0.5. If I train the model with BCE + Dice and fine-tune with lovasz softmax, within a few epochs the entire predicted segmentation converges to 0.5.

JohnMBrandt commented 5 years ago

Fixed by implementing equibatch sampling

jaewooklee93 commented 4 years ago

How about changing per_image to be True?

What's the effect of that parameter? I think it's natural to calculate loss per image, and then take its mean.

lauraset commented 3 years ago

@JohnMBrandt Hello, can you share us about how to implement equibatch sampling?