SmoothL1RegressionLoss#
- class SmoothL1RegressionLoss(beta=1.0, reduction='mean', loss_weight=1.0)[source]#
Bases:
ModuleSmooth-L1 (Huber) regression loss for continuous targets.
forward(pred, target)returnsloss_weight * smooth_l1_loss(pred, target)with the configured transition point and reduction;predandtargetmust broadcast. Registered asSmoothL1RegressionLoss– use in acriteria=[...]list or as a per-headcriterionin the instance regression losses.- Parameters:
beta (float) – Transition point between the L2 and L1 regimes. Defaults to
1.0.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="SmoothL1RegressionLoss", beta=1.0)]) >>> pred = torch.zeros(4) >>> target = torch.ones(4) # |err|=1 == beta -> 0.5 * err^2 >>> crit(pred, target) # scalar loss tensor(0.5000)