From 60cd28bdfb410539ee582963e8f22bec4f0b7182 Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Tue, 22 May 2018 17:10:04 +0000
Subject: [PATCH] Fixed seg-fault that occurred if <class_id> in labels more than classes= in the cfg-file.

---
 src/region_layer.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/region_layer.c b/src/region_layer.c
index 62c8b34..9d5fd72 100644
--- a/src/region_layer.c
+++ b/src/region_layer.c
@@ -256,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) {
@@ -293,6 +295,8 @@
         }
         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 best_iou = 0;
@@ -339,8 +343,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;

--
Gitblit v1.10.0