import torch


def jaccard(label_pred, label_gt) -> float:
    """
    Computes the jaccard score
    """
    with torch.no_grad():
        prediction_bin = torch.argmax(label_pred, dim=1)
        INTER = torch.mul(prediction_bin, label_gt).sum()
        FP = torch.mul(prediction_bin, 1 - label_gt).sum()
        FN = torch.mul(1 - prediction_bin, label_gt).sum()

        JS = float(INTER) / (float(INTER + FP + FN) + 1e-6)

    return JS