From eb45500f330ccefd6faa0771a5abd230c690189a Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Thu, 27 Jul 2017 21:36:11 +0000
Subject: [PATCH] Update Readme.md - how to use Yolo9000

---
 src/detection_layer.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/src/detection_layer.c b/src/detection_layer.c
index 1fe6767..cd98b4b 100644
--- a/src/detection_layer.c
+++ b/src/detection_layer.c
@@ -30,7 +30,12 @@
     l.truths = l.side*l.side*(1+l.coords+l.classes);
     l.output = calloc(batch*l.outputs, sizeof(float));
     l.delta = calloc(batch*l.outputs, sizeof(float));
+
+    l.forward = forward_detection_layer;
+    l.backward = backward_detection_layer;
 #ifdef GPU
+    l.forward_gpu = forward_detection_layer_gpu;
+    l.backward_gpu = backward_detection_layer_gpu;
     l.output_gpu = cuda_make_array(l.output, batch*l.outputs);
     l.delta_gpu = cuda_make_array(l.delta, batch*l.outputs);
 #endif
@@ -53,7 +58,7 @@
             int index = b*l.inputs;
             for (i = 0; i < locations; ++i) {
                 int offset = i*l.classes;
-                softmax_array(l.output + index + offset, l.classes, 1,
+                softmax(l.output + index + offset, l.classes, 1,
                         l.output + index + offset);
             }
         }
@@ -216,6 +221,35 @@
     axpy_cpu(l.batch*l.inputs, 1, l.delta, 1, state.delta, 1);
 }
 
+void get_detection_boxes(layer l, int w, int h, float thresh, float **probs, box *boxes, int only_objectness)
+{
+    int i,j,n;
+    float *predictions = l.output;
+    //int per_cell = 5*num+classes;
+    for (i = 0; i < l.side*l.side; ++i){
+        int row = i / l.side;
+        int col = i % l.side;
+        for(n = 0; n < l.n; ++n){
+            int index = i*l.n + n;
+            int p_index = l.side*l.side*l.classes + i*l.n + n;
+            float scale = predictions[p_index];
+            int box_index = l.side*l.side*(l.classes + l.n) + (i*l.n + n)*4;
+            boxes[index].x = (predictions[box_index + 0] + col) / l.side * w;
+            boxes[index].y = (predictions[box_index + 1] + row) / l.side * h;
+            boxes[index].w = pow(predictions[box_index + 2], (l.sqrt?2:1)) * w;
+            boxes[index].h = pow(predictions[box_index + 3], (l.sqrt?2:1)) * h;
+            for(j = 0; j < l.classes; ++j){
+                int class_index = i*l.classes;
+                float prob = scale*predictions[class_index+j];
+                probs[index][j] = (prob > thresh) ? prob : 0;
+            }
+            if(only_objectness){
+                probs[index][0] = scale;
+            }
+        }
+    }
+}
+
 #ifdef GPU
 
 void forward_detection_layer_gpu(const detection_layer l, network_state state)

--
Gitblit v1.10.0