Negative loss and IoU is greater than 1
I am getting a weird loss and IoU score.. Dice loss becomes negative just after 2-3 epochs, and IoU becomes greater than 1 at the same time. Why is this happening? I have already checked and my masks are binary images in {0, 1} values. Something wrong in loss function??
Thanks
Search "negative loss" in the issues as there are already a few posts that describe potential reasons for why this is.
I have the same issue. I checked that the input images pixels range from 0 to 255 and mask values are uint8 in {0, 1}. I'm currently using the diceloss loss function.
I normalized the image pixels as well using mean, std variables.. however no luck to run dice loss.. it is still in negative!! @qubvel - could you please help us here?!!
I am also facing the same issue of negative dice loss and iou_score of greater than 1.Could you please help.
Try to normalize your input pictures to [0;1], simply divide them by 255. This should give you positive values of loss and score. Check all your data to be float64 or float32.
Try to normalize your input pictures to [0;1], simply divide them by 255. This should give you positive values of loss and score. Check all your data to be float64 or float32.
sure thank you. I will try that
Normalizing both input and target images has worked for me! Thanks!
So normalizing (by dividing by 255) is really only helpful if your images are originally in the range of 0-255, and your model expects a range of 0-1. If you're having trouble with loss functions, I'd double check that the correct pre-processing method is being used for the architecture you're attempting to implement. For example, ResNets trained on ImageNet expect images between the range of 0-255; each architecture may be different.
Hello @JordanMakesMaps, I checked the preprocessing for resnets and it doesn't do anything, so if someone wants to use pretrained imagenet weights he shouldn't scale his images to the range of 0-1 because resnets expect images with range 0-255 ? Are you sure that I should not rescale them ?
I checked the paper "Deep Residual Learning for Image Recognition" I think the images were normalised, they were substracted by the mean.

Hey @luna9722, for ResNet, values were still between 0-255, though some are between 0-1, or -1-1, etc., If you check the Keras pre-processing for the ResNet architectures I believe it only substracts the mean per-pixel value (as you've also highlighted in the paper).
Thank you @JordanMakesMaps for your answer, I don't know why I was confused, you made it clear for me, thank you.
This issue happened for me and the reason was setting logit=False in the loss function by mistake.