def dice_coeff(pred, target, smooth=1):
    """
    Sorensen-Dice coefficient (DSC) metric
    @param pred: torch.tensor, model prediction
    @param target: torch.tensor, ground truth label
    @param smooth: Laplace smooth, a large value can be used to avoid overfitting
    """
    iflat, tflat = pred.view(-1), target.view(-1)
    intersection = (iflat * tflat).sum()
    return (2*intersection + smooth) / (iflat.sum() + tflat.sum() + smooth)