import torch


def dice_score(SR, GT):
    """Computes the dice coefficient between segmented and ground truth"""
    if SR.shape != GT.shape:
        raise ValueError(
            "Shape mismatch: im1 and im2 must have the same shape."
        )

    SR = torch.sigmoid(SR)
    SR = (SR > 0.5).float()

    return 2 * (SR * GT).sum() / ((SR + GT).sum() + 1e-8)