nn.L1Loss
取预测值和真实值的绝对误差的平均数。
loss ( x , y ) = 1 N ∑ i = 1 N ∣ x − y ∣ \operatorname{loss}(\mathbf{x}, \mathbf{y})=\frac{1}{N} \sum_{i=1}^{N}|\mathbf{x}-\mathbf{y}| loss(x,y)=N1i=1∑N∣x−y∣
nn.SmoothL1Loss
也叫作 Huber Loss,误差在 (-1,1) 上是平方损失,其他情况是 L1 损失。
loss ( x , y ) = 1 N { 1 2 ( x i − y i ) 2 if ∣ x i − y i ∣ < 1 ∣ x i − y i ∣ − 1 2 , otherwise \operatorname{loss}(\mathbf{x}, \mathbf{y})=\frac{1}{N}\left\{\begin{array}{cc}{\frac{1}{2}\left(\mathbf{x}_{i}-\mathbf{y}_{i}\right)^{2}} & {\text { if }\left|\mathbf{x}_{i}-\mathbf{y}_{i}\right|<1} \\ {\left|\mathbf{x}_{i}-\mathbf{y}_{i}\right|-\frac{1}{2},} & {\text { otherwise }}\end{array}\right. loss(x,y)=N1{