JunMa11 / SegLossOdyssey

A collection of loss functions for medical image segmentation
Apache License 2.0
3.76k stars 597 forks source link

when `apply_nonlin=None` calculation of GDiceLoss fails because softmax_output is not created #11

Closed neuronflow closed 3 years ago

neuronflow commented 3 years ago

when apply_nonlin=None calculation of GDiceLoss fails:

Traceback (most recent call last):
  File "path/loser.py", line 181, in <module>
    loss = criterion(prediction, label)
  File "path/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "path/SegLoss/losses_pytorch/dice_loss.py", line 123, in forward
    intersection: torch.Tensor = w * einsum("bcxyz, bcxyz->bc", softmax_output, y_onehot)
UnboundLocalError: local variable 'softmax_output' referenced before assignment
neuronflow commented 3 years ago

the same problem exists for: GDiceLossV2

my tensors already have a non linearity applied so there is no reason to do it again :)

JunMa11 commented 3 years ago

Hi @neuronflow ,

Thanks for pointing out this issue.

However, I'm currently busy with my thesis. I will try to fix it after submitting my thesis.

Before that, please try this one.

Sorry for the inconvenience.

Best, Jun

clementpoiret commented 3 years ago

I just pushed a quick PR to fix this issue :) https://github.com/JunMa11/SegLoss/pull/15

I hope it'll help