jocpae / clDice

MIT License
220 stars 28 forks source link

clloss can not be used alone, and keep 0 all the time. #17

Closed coreeey closed 2 years ago

coreeey commented 2 years ago

When i use the cldice to train a vessel segmentation network, i find that the cldice keeps 0 all the time.

class softcldice(nn.Module): def init(self, iter=3, smooth = 1.): super(softcldice, self).init() self.iter = iter self.smooth = smooth

def forward(self, y_pred, y_true):
    y_true = y_true.contiguous().unsqueeze(1).to(float) # to get the true label
    y_pred = (y_pred > 0.5).contiguous().to(float).requires_grad_() #to get the pred mask
    skel_pred = soft_skel(y_pred, self.iter)
    skel_true = soft_skel(y_true, self.iter)
    tprec = (torch.sum(torch.multiply(skel_pred, y_true)[:,1:,...])+self.smooth)/(torch.sum(skel_pred[:,1:,...])+self.smooth)    
    tsens = (torch.sum(torch.multiply(skel_true, y_pred)[:,1:,...])+self.smooth)/(torch.sum(skel_true[:,1:,...])+self.smooth)    
    cl_dice = 1.- 2.0*(tprec*tsens)/(tprec+tsens)
    return cl_dice
jocpae commented 2 years ago

Dear Coreey, it is hard to comment on this without more detail. What kind of data are you using? What is the diameter of your foreground vessels? Maybe try to increase the number of iterations as a first step and plot the resulting skeletons. Otherwise I would need more specifics.

jocpae commented 2 years ago

To be clear we also describe this in the paper. You should always combine cldice-loss with another loss function. Please see the paper for this.