一、本文介绍
本文记录的是利用Smooth L1 Loss改进YOLOv10的定位精度。Smooth L1 Loss在L1 Loss基础上对小误差进行平滑处理。
二、Smooth L1 Loss损失函数介绍
2.1 设计出发点
L1 Loss在误差接近零时梯度不连续,L2 Loss对异常值敏感,Smooth L1 Loss结合了两者的优点。
2.2 损失函数公式
Smooth L1 Loss:
smooth_l1(x) = 0.5 * x², if |x| < 1 smooth_l1(x) = |x| - 0.5, otherwise三、Smooth L1 Loss的实现代码
importtorchimporttorch.nnasnnclass