L1RegressionLoss#

class L1RegressionLoss(reduction='mean', loss_weight=1.0)[source]#

Bases: Module

Mean-absolute-error (L1) regression loss for continuous targets.

forward(pred, target) returns loss_weight * l1_loss(pred, target); pred and target must broadcast. Registered as L1RegressionLoss – use in a criteria=[...] list or as a per-head criterion.

Parameters:
  • reduction (str) – Reduction mode ("mean", "sum", "none"). Defaults to "mean".

  • loss_weight (float) – Global scale on the returned loss. Defaults to 1.0.

Example

>>> import torch
>>> from pimm.models.losses.builder import build_criteria
>>> crit = build_criteria([dict(type="L1RegressionLoss", loss_weight=1.0)])
>>> crit(torch.zeros(4), torch.ones(4))  # mean |0 - 1| = 1.0
tensor(1.)
L1RegressionLoss.forward(pred, target)[source]#