L1RegressionLoss#
- class L1RegressionLoss(reduction='mean', loss_weight=1.0)[source]#
Bases:
ModuleMean-absolute-error (L1) regression loss for continuous targets.
forward(pred, target)returnsloss_weight * l1_loss(pred, target);predandtargetmust broadcast. Registered asL1RegressionLoss– use in acriteria=[...]list or as a per-headcriterion.- 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.)