mindcv.loss

loss init

mindcv.loss.create_loss(name='CE', weight=None, reduction='mean', label_smoothing=0.0, aux_factor=0.0)[源代码]

Creates loss function

参数
  • name (str) – loss name : ‘CE’ for cross_entropy. ‘BCE’: binary cross entropy. Default: ‘CE’.

  • weight (Tensor) – Class weight. A rescaling weight given to the loss of each batch element. If given, has to be a Tensor of size ‘nbatch’. Data type must be float16 or float32.

  • reduction (str) – Apply specific reduction method to the output: ‘mean’ or ‘sum’. By default, the sum of the output will be divided by the number of elements in the output. ‘sum’: the output will be summed. Default:’mean’.

  • label_smoothing (float) – Label smoothing factor, a regularization tool used to prevent the model from overfitting when calculating Loss. The value range is [0.0, 1.0]. Default: 0.0.

  • aux_factor (float) – Auxiliary loss factor. Set aux_fuactor > 0.0 if the model has auxilary logit outputs (i.e., deep supervision), like inception_v3. Default: 0.0.

Inputs:
  • logits (Tensor or Tuple of Tensor): Input logits. Shape [N, C], where N means the number of samples, C means number of classes.

    Tuple of two input logits are supported in order (main_logits, aux_logits) for auxilary loss used in networks like inception_v3. Data type must be float16 or float32.

  • labels (Tensor): Ground truth labels. Shape: [N] or [N, C].
    1. If in shape [N], sparse labels representing the class indinces. Must be int type.

    2. shape [N, C], dense labels representing the ground truth class probability values, or the one-hot labels. Must be float type. If the loss type is BCE, the shape of labels must be [N, C].

返回

Loss function to compute the loss between the input logits and labels.

参数
  • name (str) –

  • weight (Optional[Tensor]) –

  • reduction (str) –

  • label_smoothing (float) –

  • aux_factor (float) –