mateuszbuda / brain-segmentation-pytorch

U-Net implementation in PyTorch for FLAIR abnormality segmentation in brain MRI
https://mateuszbuda.github.io/2017/12/01/brainseg.html
MIT License
722 stars 187 forks source link

Negative loss value #36

Open memani1 opened 2 years ago

memani1 commented 2 years ago

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

vksastry commented 2 years ago

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 commented 2 years ago

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]

hehuayi12138 commented 10 months ago

thanks!really useful !