brain-segmentation-pytorch icon indicating copy to clipboard operation
brain-segmentation-pytorch copied to clipboard

Negative loss value

Open memani1 opened this issue 2 years ago • 3 comments

When I train this model with the default run command python train.py

I see negative loss values and 0 Dice coefficient value

loss for step: 622 = [-0.9068316221237183]
loss for step: 623 = [-0.9329317808151245]
loss for step: 624 = [-0.9376015663146973]
Best validation mean DSC: 0.000000

This code is using Torch 1.10 on Nvidia GPU with CUDA 11. Is there something that needs fixing in the code (dataloader etc.)?

memani1 avatar Mar 03 '22 20:03 memani1

This issue arises with scikit-image = 0.19.x. The older version of skimage.transform.resize function converts the inputs from uint8 to an output of float64 and normalizes it within the function. But in the latest it produces an output of uint8 itself and does not normalize. So additional normalization of the mask is required so that it values are contained with 0s and 1s instead of a value of 255.

vksastry avatar Mar 10 '22 16:03 vksastry

Suggested changes:

def normalize_mask(mask): mask = mask / (np.max(mask)) return mask

self.volumes = [(normalize_volume(v), normalize_mask(m)) for v, m in self.volumes]

vksastry avatar Mar 10 '22 17:03 vksastry

thanks!really useful !

hehuayi12138 avatar Jan 29 '24 00:01 hehuayi12138