mlx.nn.losses.smooth_l1_loss#
- class smooth_l1_loss(predictions: array, targets: array, beta: float = 1.0, reduction: Literal['none', 'mean', 'sum'] = 'mean')#
计算 smooth L1 损失。
smooth L1 损失是 L1 损失的一个变体,当绝对差值小于
beta
时,它用平方差代替绝对差值。smooth L1 损失的公式为
\[\begin{split}l = \begin{cases} 0.5 (x - y)^2 / \beta, & \text{如果 } |x - y| < \beta \\ |x - y| - 0.5 \beta, & \text{否则} \end{cases}\end{split}\]