Pau*_*Guo 5 machine-learning object-detection computer-vision deep-learning yolo
我打算编写自己的 YOLOv3 实现,并提出损失函数的一些问题。原始论文提到他在类别预测部分使用了二元交叉熵,这就是我所做的。
我尝试通过原始暗网代码阅读一些代码,但没有找到任何与 BCE 丢失相关的内容。我还进一步阅读了一些使用 Keras、Pytorch 和 TensorFlow 的方法。每个人似乎对损失函数都有自己的看法。有的只用MSE来估计宽度和高度,有的用BCE,有的用MSE来估计x,y,w,h,有的用BCE。
这是我的一些代码:
loss_x = self.mse_loss(x[mask], tx[mask])
loss_y = self.mse_loss(y[mask], ty[mask])
loss_w = self.mse_loss(w[mask], tw[mask])
loss_h = self.mse_loss(h[mask], th[mask])
loss_conf = self.bce_loss(pred_conf[conf_mask_false], tconf[conf_mask_false]) + self.bce_loss(pred_conf[conf_mask_true],tconf[conf_mask_true])
loss_cls = (1 / nB) * self.ce_loss(pred_cls[mask],torch.argmax(tcls[mask], 1))
loss = loss_x + loss_y + loss_w + loss_h + loss_conf + loss_cls
Run Code Online (Sandbox Code Playgroud)
由于损失函数在训练中起着重要作用。我希望有人能帮我解决这个问题。
Yolo v3的损失函数,看src/yolo_layer.c
盒子的增量,第 93 行
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]);
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;
}
Run Code Online (Sandbox Code Playgroud)
Delta 班次,111 号线
void delta_yolo_class(float *output, float *delta, int index, int class, int classes, int stride, float *avg_cat)
{
int n;
if (delta[index]){
delta[index + stride*class] = 1 - output[index + stride*class];
if(avg_cat) *avg_cat += output[index + stride*class];
return;
}
for(n = 0; n < classes; ++n){
delta[index + stride*n] = ((n == class)?1 : 0) - output[index + stride*n];
if(n == class && avg_cat) *avg_cat += output[index + stride*n];
}
}
Run Code Online (Sandbox Code Playgroud)
对象性的增量,第 178 行
l.delta[obj_index] = 0 - l.output[obj_index];
if (best_iou > l.ignore_thresh) {
l.delta[obj_index] = 0;
Run Code Online (Sandbox Code Playgroud)
和
l.delta[obj_index] = 1 - l.output[obj_index];
Run Code Online (Sandbox Code Playgroud)
损失=平方和
*(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2);
Run Code Online (Sandbox Code Playgroud)
无论如何,我只是让您了解一下 Yolo V3 中的损失函数。有关详细说明,您应该关注此 github 讨论:
https://github.com/AlexeyAB/darknet/issues/1695#issuecomment-426016524
和
https://github.com/AlexeyAB/darknet/issues/1845#issuecomment-434079752
| 归档时间: |
|
| 查看次数: |
9179 次 |
| 最近记录: |