SmoothL1Loss¶
- class paddle.nn. SmoothL1Loss ( reduction='mean', delta=1.0, name=None ) [source]
-
This operator calculates smooth_l1_loss. Creates a criterion that uses a squared term if the absolute element-wise error falls below 1 and an L1 term otherwise. In some cases it can prevent exploding gradients and it is more robust and less sensitivity to outliers. Also known as the Huber loss:
loss(x,y)=1n∑iziwhere zi is given by:
zi={0.5(xi−yi)2if|xi−yi|<δδ∗|xi−yi|−0.5∗δ2otherwise- Parameters
-
reduction (str, optional) – Indicate how to average the loss by batch_size, the candicates are
'none'
|'mean'
|'sum'
. Ifreduction
is'mean'
, the reduced mean loss is returned; Ifreduction
is'sum'
, the reduced sum loss is returned. Ifreduction
is'none'
, the unreduced loss is returned. Default is'mean'
.delta (float, optional) – Specifies the hyperparameter δ to be used. The value determines how large the errors need to be to use L1. Errors smaller than delta are minimized with L2. Parameter is ignored for negative/zero values. Default value is 1.0.
name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.
Call Parameters:
input (Tensor): Input tensor, the data type is float32 or float64. Shape is (N, C), where C is number of classes, and if shape is more than 2D, this is (N, C, D1, D2,…, Dk), k >= 1.
label (Tensor): Label tensor, the data type is float32 or float64. The shape of label is the same as the shape of input.
- Returns
-
Tensor, The tensor storing the smooth_l1_loss of input and label.
Examples
>>> import paddle >>> paddle.seed(2023) >>> input = paddle.rand([3, 3]).astype("float32") >>> label = paddle.rand([3, 3]).astype("float32") >>> loss = paddle.nn.SmoothL1Loss() >>> output = loss(input, label) >>> print(output) Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, 0.08307374)
-
forward
(
input,
label
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments