Skip to content

sum

Weighted sum of several (logits, target) losses.

Classes:

  • SumLoss –

    Weighted sum of several loss modules sharing a (logits, target) signature.

SumLoss [source] ¶

SumLoss(
    losses: Sequence[Module],
    weights: Optional[Sequence[float]] = None,
)

Bases: Module

Weighted sum of several loss modules sharing a (logits, target) signature.

Each sub-loss is evaluated on the same inputs and the results are added (e.g. cross-entropy plus Lovász), each scaled by its weight when weights is given.

Parameters:

  • losses (Sequence[Module]) –

    The loss modules to sum.

  • weights (Optional[Sequence[float]], default: None ) –

    One scalar per loss; None adds them as they are.

Methods:

  • forward –

    Compute the weighted sum of the sub-losses.

forward [source] ¶

forward(logits: Tensor, target: Tensor) -> Tensor

Compute the weighted sum of the sub-losses.