From 6056b835eb76b8a078aab18db3e7aba87314f4ce Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Thu, 19 Apr 2018 01:34:26 +0300 Subject: [PATCH] Fixed Focal-loss --- src/yolo_layer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/yolo_layer.c b/src/yolo_layer.c index ad624261..b2443bab 100644 --- a/src/yolo_layer.c +++ b/src/yolo_layer.c @@ -121,12 +121,13 @@ void delta_yolo_class(float *output, float *delta, int index, int class_id, int if (focal_loss) { // Focal Loss float alpha = 0.5; // 0.25 or 0.5 - //float gamma = 2; // hardcoded in many places of the grad-formula + //float gamma = 2; // hardcoded in many places of the grad-formula int ti = index + stride*class_id; float pt = output[ti] + 0.000000000000001F; - //float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832 - float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss + // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiItKDEteCkqKDIqeCpsb2coeCkreC0xKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMH1d + float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832 + //float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss for (n = 0; n < classes; ++n) { delta[index + stride*n] = (((n == class_id) ? 1 : 0) - output[index + stride*n]);