From d7fd2acf0582020de87f49d8863d39d1744a858c Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@burninator.cs.washington.edu>
Date: Thu, 23 Jun 2016 05:31:17 +0000
Subject: [PATCH] Merge branch 'master' of https://github.com/pjreddie/darknet

---
 src/detection_layer.c |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/src/detection_layer.c b/src/detection_layer.c
index 33f4f0b..8b4045a 100644
--- a/src/detection_layer.c
+++ b/src/detection_layer.c
@@ -50,11 +50,9 @@
             int index = b*l.inputs;
             for (i = 0; i < locations; ++i) {
                 int offset = i*l.classes;
-                softmax_array(l.output + index + offset, l.classes,
+                softmax_array(l.output + index + offset, l.classes, 1,
                         l.output + index + offset);
             }
-            int offset = locations*l.classes;
-            activate_array(l.output + index + offset, locations*l.n*(1+l.coords), LOGISTIC);
         }
     }
     if(state.train){
@@ -133,6 +131,9 @@
                         best_index = 0;
                     }
                 }
+                if(l.random && *(state.net.seen) < 64000){
+                    best_index = rand()%l.n;
+                }
 
                 int box_index = index + locations*(l.classes + l.n) + (i*l.n + best_index) * l.coords;
                 int tbox_index = truth_index + 1 + l.classes;
@@ -146,7 +147,7 @@
                 }
                 float iou  = box_iou(out, truth);
 
-                //printf("%d", best_index);
+                //printf("%d,", best_index);
                 int p_index = index + locations*l.classes + i*l.n + best_index;
                 *(l.cost) -= l.noobject_scale * pow(l.output[p_index], 2);
                 *(l.cost) += l.object_scale * pow(1-l.output[p_index], 2);
@@ -170,11 +171,38 @@
                 avg_iou += iou;
                 ++count;
             }
-            if(l.softmax){
-                gradient_array(l.output + index + locations*l.classes, locations*l.n*(1+l.coords), 
-                        LOGISTIC, l.delta + index + locations*l.classes);
-            }
         }
+
+        if(0){
+            float *costs = calloc(l.batch*locations*l.n, sizeof(float));
+            for (b = 0; b < l.batch; ++b) {
+                int index = b*l.inputs;
+                for (i = 0; i < locations; ++i) {
+                    for (j = 0; j < l.n; ++j) {
+                        int p_index = index + locations*l.classes + i*l.n + j;
+                        costs[b*locations*l.n + i*l.n + j] = l.delta[p_index]*l.delta[p_index];
+                    }
+                }
+            }
+            int indexes[100];
+            top_k(costs, l.batch*locations*l.n, 100, indexes);
+            float cutoff = costs[indexes[99]];
+            for (b = 0; b < l.batch; ++b) {
+                int index = b*l.inputs;
+                for (i = 0; i < locations; ++i) {
+                    for (j = 0; j < l.n; ++j) {
+                        int p_index = index + locations*l.classes + i*l.n + j;
+                        if (l.delta[p_index]*l.delta[p_index] < cutoff) l.delta[p_index] = 0;
+                    }
+                }
+            }
+            free(costs);
+        }
+
+
+        *(l.cost) = pow(mag_array(l.delta, l.outputs * l.batch), 2);
+
+
         printf("Detection Avg IOU: %f, Pos Cat: %f, All Cat: %f, Pos Obj: %f, Any Obj: %f, count: %d\n", avg_iou/count, avg_cat/count, avg_allcat/(count*l.classes), avg_obj/count, avg_anyobj/(l.batch*locations*l.n), count);
     }
 }
@@ -201,7 +229,7 @@
         cuda_pull_array(state.truth, truth_cpu, num_truth);
     }
     cuda_pull_array(state.input, in_cpu, l.batch*l.inputs);
-    network_state cpu_state;
+    network_state cpu_state = state;
     cpu_state.train = state.train;
     cpu_state.truth = truth_cpu;
     cpu_state.input = in_cpu;

--
Gitblit v1.10.0