From f762e6adb50d0a7eb72825b322e7d4192ae29ef3 Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Sat, 03 Feb 2018 12:38:31 +0000
Subject: [PATCH] Merge pull request #357 from rajendraarora16/new-changes-darknet

---
 src/region_layer.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/region_layer.c b/src/region_layer.c
index 5e8387d..7772bc3 100644
--- a/src/region_layer.c
+++ b/src/region_layer.c
@@ -44,7 +44,7 @@
     l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs);
 #endif
 
-    fprintf(stderr, "Region Layer\n");
+    fprintf(stderr, "detection\n");
     srand(0);
 
     return l;
@@ -196,7 +196,8 @@
                 if(truth.x > 100000 && truth.y > 100000){
                     for(n = 0; n < l.n*l.w*l.h; ++n){
                         int index = size*n + b*l.outputs + 5;
-                        float p = get_hierarchy_probability(l.output + index, l.softmax_tree, class);
+                        float scale =  l.output[index-1];
+                        float p = scale*get_hierarchy_probability(l.output + index, l.softmax_tree, class);
                         if(p > maxp){
                             maxp = p;
                             maxi = n;
@@ -324,7 +325,7 @@
     axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, state.delta, 1);
 }
 
-void get_region_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness)
+void get_region_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness, int *map)
 {
     int i,j,n;
     float *predictions = l.output;
@@ -348,8 +349,13 @@
 
                 hierarchy_predictions(predictions + class_index, l.classes, l.softmax_tree, 0);
                 int found = 0;
-                for(j = l.classes - 1; j >= 0; --j){
-                    if(1){
+                if(map){
+                    for(j = 0; j < 200; ++j){
+                        float prob = scale*predictions[class_index+map[j]];
+                        probs[index][j] = (prob > thresh) ? prob : 0;
+                    }
+                } else {
+                    for(j = l.classes - 1; j >= 0; --j){
                         if(!found && predictions[class_index + j] > .5){
                             found = 1;
                         } else {
@@ -357,12 +363,9 @@
                         }
                         float prob = predictions[class_index+j];
                         probs[index][j] = (scale > thresh) ? prob : 0;
-                    }else{
-                        float prob = scale*predictions[class_index+j];
-                        probs[index][j] = (prob > thresh) ? prob : 0;
                     }
                 }
-            }else{
+            } else {
                 for(j = 0; j < l.classes; ++j){
                     float prob = scale*predictions[class_index+j];
                     probs[index][j] = (prob > thresh) ? prob : 0;
@@ -406,6 +409,7 @@
         cuda_pull_array(state.truth, truth_cpu, num_truth);
     }
     cuda_pull_array(l.output_gpu, in_cpu, l.batch*l.inputs);
+	cudaStreamSynchronize(get_cuda_stream());
     network_state cpu_state = state;
     cpu_state.train = state.train;
     cpu_state.truth = truth_cpu;
@@ -415,6 +419,7 @@
     free(cpu_state.input);
     if(!state.train) return;
     cuda_push_array(l.delta_gpu, l.delta, l.batch*l.outputs);
+	cudaStreamSynchronize(get_cuda_stream());
     if(cpu_state.truth) free(cpu_state.truth);
 }
 

--
Gitblit v1.10.0