YOLOV3-损失函数及其源代码理解(yolo_layer.c)
讲得好
https://github.com/AlexeyAB/darknet/issues/821
x,y,w,h 损失
原版的bbox损失为MSE,其后又GIOU,DIOU…
delta即为求完损失的梯度
公式对应图
思路及具体求法:
https://github.com/AlexeyAB/darknet/issues/2287
https://blog.csdn.net/qq_34199326/article/details/84109828
float delta_yolo_box(box truth, float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, float *delta, float scale, int stride)
{
box pred = get_yolo_box(x, biases, n, index, i, j, lw, lh, w, h, stride);
float iou = box_iou(pred, truth);
float tx = (truth.x*lw - i);
float ty = (truth.y*lh - j);
float tw = log(truth.w*w / biases[2*n]);
float th = log(truth.h*h / biases[2*n + 1]);
scale = 2 - groundtruth.w * groundtruth.h //关于这个为什么相等的问题,总得来说就是为了小目标delta可以大一些。可以参看https://github.com/AlexeyAB/darknet/issues/1532
delta[index + 0*stride] = scale * (tx - x[index + 0*stride]);
delta[index + 1*stride] = scale * (ty - x[index + 1*stride]);
delta[index + 2*stride] = scale * (tw - x[index + 2*stride]);
delta[index + 3*stride] = scale * (th - x[index + 3*stride]);
return iou;
}
类别损失
讲的好
https://github.com/AlexeyAB/darknet/issues/1695
置信度损失
总损失
看完链接基本就都明白了