diffengine.models.losses.cross_entropy_loss

Module Contents

Classes

CrossEntropyLoss

CrossEntropy loss.

class diffengine.models.losses.cross_entropy_loss.CrossEntropyLoss(loss_weight=1.0, reduction='mean', ignore_index=-100, loss_name='cross_entropy')[source]

Bases: diffengine.models.losses.base.BaseLoss

CrossEntropy loss.

Args:

loss_weight (float, optional): Weight of this loss item.

Defaults to 1..

reduction: (str): The reduction method for the loss.

Defaults to ‘mean’.

ignore_index (int): Specifies a target value that is ignored.

Defaults to -100.

loss_name (str, optional): Name of the loss item. If you want this loss

item to be included into the backward graph, loss_ must be the prefix of the name. Defaults to ‘l2’.

forward(pred, gt, weight=None)[source]

Forward function.

Args:

pred (torch.Tensor): The predicted tensor. gt (torch.Tensor): The ground truth tensor. weight (torch.Tensor | None, optional): The loss weight.

Defaults to None.

Returns:

torch.Tensor: loss

Parameters:
  • pred (torch.Tensor) –

  • gt (torch.Tensor) –

  • weight (torch.Tensor | None) –

Return type:

torch.Tensor

Parameters:
  • loss_weight (float) –

  • reduction (str) –

  • ignore_index (int) –

  • loss_name (str) –