utils/metrics.py
def dice_coeff_2label(pred, target):
    """This definition generalize to real valued pred and target vector.
    This should be differentiable.
    pred: tensor with first dimension as batch
    target: tensor with first dimension as batch
    """

    target = target.data.cpu()
    pred = torch.sigmoid(pred)
    pred = pred.data.cpu()
    pred[pred > 0.75] = 1
    pred[pred <= 0.75] = 0
    # print target.shape
    # print pred.shape
    return dice_coefficient_numpy(pred[:, 0, ...], target[:, 0, ...]), dice_coefficient_numpy(pred[:, 1, ...], target[:, 1, ...])
This definition generalize to real valued pred and target vector.
    This should be differentiable.
    pred: tensor with first dimension as batch
    target: tensor with first dimension as batch
    
This definition generalize to real valued pred and target vector.
This should be differentiable.
pred: tensor with first dimension as batch
target: tensor with first dimension as batch
This definition generalize to real valued pred and target vector . This should be differentiable . pred : tensor with first dimension as batch target : tensor with first dimension as batch
def dice_coeff_2label(pred, target):
    target = target.data.cpu()
    pred = torch.sigmoid(pred)
    pred = pred.data.cpu()
    pred[pred > 0.75] = 1
    pred[pred <= 0.75] = 0
    return dice_coefficient_numpy(pred[:, 0, ...], target[:, 0, ...]), dice_coefficient_numpy(pred[:, 1, ...], target[:, 1, ...])
def dice_coeff_2label ( pred , target ) : target = target . data . cpu ( ) pred = torch . sigmoid ( pred ) pred = pred . data . cpu ( ) pred [ pred > 0.75 ] = 1 pred [ pred <= 0.75 ] = 0 return dice_coefficient_numpy ( pred [ : , 0 , ... ] , target [ : , 0 , ... ] ) , dice_coefficient_numpy ( pred [ : , 1 , ... ] , target [ : , 1 , ... ] )
This definition generalize to real valued pred and target vector.
This definition generalize to real valued pred and target vector .
"""This definition generalize to real valued pred and target vector.
    This should be differentiable.
    pred: tensor with first dimension as batch
    target: tensor with first dimension as batch
    """ # print target.shape # print pred.shape
pred
target