class
SmoothL1Loss
extends
ModuleSmoothL1Loss(reduction: Reduction = 'mean', beta: float = 1.0)Smooth L1 loss — a -parameterised Huber loss.
This loss is equivalent to HuberLoss with
but uses a slightly different normalisation convention. The per-element
form is:
When this coincides exactly with the Huber loss.
Parameters
reductionstr= 'mean''none' | 'mean' (default) | 'sum'.betafloat= 1.0Transition threshold between the quadratic and linear regions.
Default
1.0.Attributes
reductionstrThe reduction mode.
betafloatThe threshold .
Notes
- Input
x: . - Target
y: — same shape asx. - Output : scalar for
'mean'/'sum'; for'none'.
- Smooth L1 is commonly used in object detection (bounding-box regression) because it is less sensitive to outlier predictions than MSE while still being differentiable everywhere.
- Setting approaches MAE; approaches MSE (for bounded residuals).
Examples
Default \beta = 1:
>>> import lucid
>>> import lucid.nn as nn
>>> criterion = nn.SmoothL1Loss()
>>> x = lucid.tensor([0.5, 2.0, -1.0])
>>> y = lucid.tensor([0.0, 0.0, 0.0])
>>> loss = criterion(x, y)
Tighter quadratic region (\beta = 0.5):
>>> import lucid
>>> import lucid.nn as nn
>>> criterion = nn.SmoothL1Loss(beta=0.5)
>>> x = lucid.tensor([0.3, 1.5, -0.2])
>>> y = lucid.tensor([0.0, 0.0, 0.0])
>>> loss = criterion(x, y)Used by 1
Constructors
1Instance methods
2Return a string representation of the layer's configuration.