def dice_coefficient(outputs, targets, eps=1.0):
    """Calculates the Dice coefficient between the predicted and target masks.

    More information:
        - https://en.wikipedia.org/wiki/Sørensen–Dice_coefficient

    Args:
        outputs (torch.tensor): Outputs of the model (N x 1 x H x W).
        targets (torch.tensor): Manual segmentations (N x H x W).
        eps (float, optional): Smooth parameter (avoid zero divisions). Defaults to 1.

    Returns:
        (float): Dice coefficient.
    """
    outputs = outputs.contiguous().view(-1)
    targets = targets.contiguous().view(-1)

    intersection = (outputs * targets).sum()
    union = outputs.sum() + targets.sum()

    return ((2 * intersection + eps) / (union + eps))