Hi all,
I am trying to implement a weighted binary cross entropy loss function with dice loss, basically:
total_loss = Weighted_bce_loss + dice_loss
I am using the code below: (SR - segmentation result, GT - ground truth)
def bce_dice_loss(GT, SR):
SR.flatten()
GT.flatten()
criterion = torch.nn.BCELoss()

loss = criterion(GT, SR) + dice_coef_loss(GT, SR)
return loss

def dice_coef_loss(GT, SR):
SR.flatten()
GT.flatten()
loss = 1 - dice_coeff(GT, SR)
return loss
def dice_coeff(GT, SR):
smooth = 1.
GT.flatten()
SR.flatten()
production = GT * SR
intersection = production.sum()

return (2. * intersection + smooth) / (GT.sum() + SR.sum() + smooth)

I am doing an medical image segmentation and I deal with a highly imbalanced dataset. In my error loss function (in the BCE part) I want to penalize False Negatives in order to get a higher Recall value.
Does anyone has an idea how to proceed with this?
Thank you in advance