Multiple Objective Loss

This module allows to combine multiple loss functions into a single loss function.

Class

class uotod.loss.MultipleObjectiveLoss(losses: List[_Loss] = None, weights: List[float] = None)

Creates a criterion that combines several losses with different weights.

\[\text{loss} = \sum_{i=1}^n w_i \text{loss}_i\]
Parameters:
  • losses (List[_Loss]) – list of losses, with reduction=”none” for all losses

  • weights (List[float]) – list of weights for the losses

Returns:

weighted sum of the losses

Return type:

Tensor (float)

Example:
>>> import torch
>>> from uotod.loss import MultipleObjectiveLoss, IoULoss
>>> loss = MultipleObjectiveLoss(
>>>     [IoULoss(reduction="none"), torch.nn.L1Loss(reduction="none")],
>>>     [1., 2.]
>>> )
forward(input: Tensor, target: Tensor) Tensor
Parameters:
  • input (Tensor of shape (batch_size, ...)) – input tensor

  • target (Tensor of shape (batch_size, ...)) – target tensor

Returns:

weighted sum of the losses

Return type:

Tensor (float)

reduction: str