(loss, weight=None, reduction='mean', avg_factor=None)
return loss
Apply element-wise weight and reduce loss.

    Args:
        loss (Tensor): Element-wise loss.
        weight (Tensor): Element-wise weights.
        reduction (str): Same as built-in losses of PyTorch.
        avg_factor (float): Avarage factor when computing the mean of losses.

    Returns:
        Tensor: Processed loss values.
Apply element-wise weight and reduce loss.
Apply element - wise weight and reduce loss .
def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None):
    """Apply element-wise weight and reduce loss.

    Args:
        loss (Tensor): Element-wise loss.
        weight (Tensor): Element-wise weights.
        reduction (str): Same as built-in losses of PyTorch.
        avg_factor (float): Avarage factor when computing the mean of losses.

    Returns:
        Tensor: Processed loss values.
    """
    # if weight is specified, apply element-wise weight
    if weight is not None:
        loss = loss * weight

    # if avg_factor is not specified, just reduce the loss
    if avg_factor is None:
        loss = reduce_loss(loss, reduction)
    else:
        # if reduction is mean, then average the loss by avg_factor
        if reduction == 'mean':
            loss = loss.sum() / avg_factor
        # if reduction is 'none', then do nothing, otherwise raise an error
        elif reduction != 'none':
            raise ValueError('avg_factor can not be used with reduction="sum"')
    return loss
def weight_reduce_loss ( loss , weight = None , reduction = 'mean' , avg_factor = None ) : # if weight is specified, apply element-wise weight if weight is not None : loss = loss * weight # if avg_factor is not specified, just reduce the loss if avg_factor is None : loss = reduce_loss ( loss , reduction ) else : # if reduction is mean, then average the loss by avg_factor if reduction == 'mean' : loss = loss . sum ( ) / avg_factor # if reduction is 'none', then do nothing, otherwise raise an error elif reduction != 'none' : raise ValueError ( 'avg_factor can not be used with reduction="sum"' ) return loss