Alexey
2018-06-19 3a33d00d22ef55247fe379b8e6c53850f43a32a8
src/region_layer.c
@@ -136,8 +136,9 @@
         int ti = index + 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 + n] = scale * (((n == class_id) ? 1 : 0) - output[index + n]);
@@ -255,6 +256,8 @@
                    int best_class_id = -1;
                    for(t = 0; t < l.max_boxes; ++t){
                        box truth = float_to_box(state.truth + t*5 + b*l.truths);
                  int class_id = state.truth[t * 5 + b*l.truths + 4];
                  if (class_id >= l.classes) continue; // if label contains class_id more than number of classes in the cfg-file
                        if(!truth.x) break;
                        float iou = box_iou(pred, truth);
                        if (iou > best_iou) {
@@ -292,6 +295,12 @@
        }
        for(t = 0; t < l.max_boxes; ++t){
            box truth = float_to_box(state.truth + t*5 + b*l.truths);
         int class_id = state.truth[t * 5 + b*l.truths + 4];
         if (class_id >= l.classes) {
            printf(" Warning: in txt-labels class_id=%d >= classes=%d in cfg-file. In txt-labels class_id should be [from 0 to %d] \n", class_id, l.classes, l.classes-1);
            getchar();
            continue; // if label contains class_id more than number of classes in the cfg-file
         }
            if(!truth.x) break;
            float best_iou = 0;
@@ -338,8 +347,6 @@
                l.delta[best_index + 4] = l.object_scale * (iou - l.output[best_index + 4]) * logistic_gradient(l.output[best_index + 4]);
            }
            int class_id = state.truth[t*5 + b*l.truths + 4];
            if (l.map) class_id = l.map[class_id];
            delta_region_class(l.output, l.delta, best_index + 5, class_id, l.classes, l.softmax_tree, l.class_scale, &avg_cat, l.focal_loss);
            ++count;
@@ -533,7 +540,7 @@
         int box_index = entry_index(l, 0, n*l.w*l.h + i, 0);
         int mask_index = entry_index(l, 0, n*l.w*l.h + i, 4);
         float scale = l.background ? 1 : predictions[obj_index];
         dets[index].bbox = get_region_box(predictions, l.biases, n, box_index, col, row, l.w, l.h, l.w*l.h);
         dets[index].bbox = get_region_box(predictions, l.biases, n, box_index, col, row, l.w, l.h);// , l.w*l.h);
         dets[index].objectness = scale > thresh ? scale : 0;
         if (dets[index].mask) {
            for (j = 0; j < l.coords - 4; ++j) {
@@ -544,7 +551,7 @@
         int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + !l.background);
         if (l.softmax_tree) {
            hierarchy_predictions(predictions + class_index, l.classes, l.softmax_tree, 0, l.w*l.h);
            hierarchy_predictions(predictions + class_index, l.classes, l.softmax_tree, 0);// , l.w*l.h);
            if (map) {
               for (j = 0; j < 200; ++j) {
                  int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + 1 + map[j]);