I’m trying to understand the implementation of the dice coefficient which is defined by:
I would like to know: What does this ∩ sign means?
Also I have an implementation of the function in Pytorch:
def dice_coeff(pred, target): smooth = 1. num = pred.size(0) m1 = pred.view(num, -1) # Flatten m2 = target.view(num, -1) # Flatten intersection = (m1 * m2).sum() return (2. * intersection + smooth) / (m1.sum() + m2.sum() + smooth) class SoftDiceLoss(nn.Module): def __init__(self, weight=None, size_average=True): super(SoftDiceLoss, self).__init__() def forward(self, logits, targets): probs = F.sigmoid(logits) num = targets.size(0) # Number of batches score = dice_coeff(probs, targets) score = 1 - score.sum() / num return score
If I try to map the math formula to the code the ∩ sign is actually a multiplication and |X| is actually taking the sum of the matrice right?
One last question: The author used a “smooth” factor. Why do we want to do that?