mmseg/models/losses/bceloss.py
def bi_cross_entropy(pred,
                         label,
                         weight=None,
                         reduction='mean',
                         avg_factor=None,
                         ignore_index=255):
    """Calculate the binary CrossEntropy loss.

    Args:
        pred (torch.Tensor): The prediction with shape (N, 1).
        label (torch.Tensor): The learning label of the prediction.
        weight (torch.Tensor, optional): Sample-wise loss weight.
        reduction (str, optional): The method used to reduce the loss.
            Options are "none", "mean" and "sum".
        avg_factor (int, optional): Average factor that is used to average
            the loss. Defaults to None.
        class_weight (list[float], optional): The weight for each class.
        ignore_index (int | None): The label index to be ignored. Default: 255

    Returns:
        torch.Tensor: The calculated loss
    """
    
    #print(pred.shape)
    if pred.dim() != label.dim():
        assert (pred.dim() == 2 and label.dim() == 1) or (
                pred.dim() == 4 and label.dim() == 3), \
            'Only pred shape [N, C], label shape [N] or pred shape [N, C, ' \
            'H, W], label shape [N, H, W] are supported'
        label, weight = _expand_onehot_labels(label, weight, pred.shape,
                                              ignore_index)
    # weighted element-wise losses
#    if weight is not None:
#        weight = weight.float()
#    loss = F.binary_cross_entropy_with_logits(
#        pred, label.float(), reduction='none')
    loss = F.binary_cross_entropy(
        pred, label.float(), reduction='mean')
    # do the reduction for the weighted loss
#    loss = weight_reduce_loss(
#        loss, weight, reduction=reduction, avg_factor=avg_factor)
   
   
    return loss
Calculate the binary CrossEntropy loss.

    Args:
        pred (torch.Tensor): The prediction with shape (N, 1).
        label (torch.Tensor): The learning label of the prediction.
        weight (torch.Tensor, optional): Sample-wise loss weight.
        reduction (str, optional): The method used to reduce the loss.
            Options are "none", "mean" and "sum".
        avg_factor (int, optional): Average factor that is used to average
            the loss. Defaults to None.
        class_weight (list[float], optional): The weight for each class.
        ignore_index (int | None): The label index to be ignored. Default: 255

    Returns:
        torch.Tensor: The calculated loss
    
Calculate the binary CrossEntropy loss.
Calculate the binary CrossEntropy loss .
def bi_cross_entropy(pred,
                         label,
                         weight=None,
                         reduction='mean',
                         avg_factor=None,
                         ignore_index=255):
    if pred.dim() != label.dim():
        assert (pred.dim() == 2 and label.dim() == 1) or (
                pred.dim() == 4 and label.dim() == 3), \
            'Only pred shape [N, C], label shape [N] or pred shape [N, C, ' \
            'H, W], label shape [N, H, W] are supported'
        label, weight = _expand_onehot_labels(label, weight, pred.shape,
                                              ignore_index)
    loss = F.binary_cross_entropy(
        pred, label.float(), reduction='mean')
    return loss
def bi_cross_entropy ( pred , label , weight = None , reduction = 'mean' , avg_factor = None , ignore_index = 255 ) : if pred . dim ( ) != label . dim ( ) : assert ( pred . dim ( ) == 2 and label . dim ( ) == 1 ) or ( pred . dim ( ) == 4 and label . dim ( ) == 3 ) , 'Only pred shape [N, C], label shape [N] or pred shape [N, C, ' 'H, W], label shape [N, H, W] are supported' label , weight = _expand_onehot_labels ( label , weight , pred . shape , ignore_index ) loss = F . binary_cross_entropy ( pred , label . float ( ) , reduction = 'mean' ) return loss
Calculate the binary CrossEntropy loss.
Calculate the binary CrossEntropy loss .
"""Calculate the binary CrossEntropy loss.

    Args:
        pred (torch.Tensor): The prediction with shape (N, 1).
        label (torch.Tensor): The learning label of the prediction.
        weight (torch.Tensor, optional): Sample-wise loss weight.
        reduction (str, optional): The method used to reduce the loss.
            Options are "none", "mean" and "sum".
        avg_factor (int, optional): Average factor that is used to average
            the loss. Defaults to None.
        class_weight (list[float], optional): The weight for each class.
        ignore_index (int | None): The label index to be ignored. Default: 255

    Returns:
        torch.Tensor: The calculated loss
    """ #print(pred.shape) # weighted element-wise losses #    if weight is not None: #        weight = weight.float() #    loss = F.binary_cross_entropy_with_logits( #        pred, label.float(), reduction='none') # do the reduction for the weighted loss #    loss = weight_reduce_loss( #        loss, weight, reduction=reduction, avg_factor=avg_factor)
The calculated loss
The calculated loss
torch.Tensor
pred
The prediction with shape (N, 1).
The prediction with shape ( N 1 ) .
label
The learning label of the prediction.
The learning label of the prediction .
weight
Sample-wise loss weight.
Sample - wise loss weight .
reduction
The method used to reduce the loss.
Options are "none", "mean" and "sum".
The method used to reduce the loss . Options are " none " " mean " and " sum " .
avg_factor
Average factor that is used to average
the loss. Defaults to None.
Average factor that is used to average the loss . Defaults to None .
ignore_index
The label index to be ignored.
The label index to be ignored .
class_weight
The weight for each class.
The weight for each class .