-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Negative total loss #183
Comments
It is ok, because you provide weights larger than 1. You can norm weight to make loss stay positive, but it does not necessary. P.S. be careful with loss absolute value, fairly I recommend to set weights in range (0..1) |
You mean instead of |
First of all, weights are optional, you can not provide them at all (automatically will be set all weights to 1). But if you would like to weight classes - yes make something like np.array([0.1, 0.5, 0.2, 0.05]) |
I have just check losses code and it should not be negative with any weights, if masks are in range (0..1). Check your code again) |
I confirmed that the masks are between 0-1 by running the following code just before
The code I used for this is attached. Note that I made some slight changes to |
@qubvel |
@jovahe |
@qubvel OK,thanks |
@za13 @qubvel Hello!I hava the same problem when I set classweight[1.5897457025300863, 19.558464414520287, 32.333179824234826, 13.486144037069105, 0.0, 17.706329452750897, 40.07563246575418].My loss is total_loss = dice_loss + (1 * focal_loss). I am sure my mask is between 0 or 1.The classweight calculation method is:
So,Have you solved your problem?@za13 And what is your suggestion? @qubvel . Thank you!!! |
I'm doing segmentation on images with 3 classes, instead of 2. So I changed
dice_loss = sm.losses.DiceLoss(class_weights=np.array([1, 2, 0.5]))
to
dice_loss = sm.losses.DiceLoss(class_weights=np.array([1, 2, 3, 0.5]))
I've noticed that although the validation losses have stayed positive and are decreasing, the training losses went from positive and decreased to negative and continue to be more negative:
Despite the negative training loss, the predictions from the test set continue to improve as the epoch number increases
I already checked that the masks are in 0-1 instead of 0-255
Is this ok? Or is this a sign that there's something wrong with the code or my setup?
The text was updated successfully, but these errors were encountered: