SmoothL1RegressionLoss#

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

Bases: Module

Smooth-L1 (Huber) regression loss for continuous targets.

forward(pred, target) returns loss_weight * smooth_l1_loss(pred, target) with the configured transition point and reduction; pred and target must broadcast. Registered as SmoothL1RegressionLoss – use in a criteria=[...] list or as a per-head criterion in 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)
SmoothL1RegressionLoss.forward(pred, target)[source]#