From d8adaf8ea6a31a380f6bf1fe65e88b661d3bb51e Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 21 Oct 2016 20:16:43 +0000
Subject: [PATCH] tree stuff
---
src/region_layer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/src/region_layer.c b/src/region_layer.c
index 24d3169..5f8b3cc 100644
--- a/src/region_layer.c
+++ b/src/region_layer.c
@@ -1,6 +1,5 @@
#include "region_layer.h"
#include "activations.h"
-#include "softmax_layer.h"
#include "blas.h"
#include "box.h"
#include "cuda.h"
@@ -34,7 +33,11 @@
l.biases[i] = .5;
}
+ l.forward = forward_region_layer;
+ l.backward = backward_region_layer;
#ifdef GPU
+ l.forward_gpu = forward_region_layer_gpu;
+ l.backward_gpu = backward_region_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
@@ -95,7 +98,7 @@
int index = size*i + b*l.outputs;
l.output[index + 4] = logistic_activate(l.output[index + 4]);
if(l.softmax){
- softmax_array(l.output + index + 5, l.classes, 1, l.output + index + 5);
+ softmax(l.output + index + 5, l.classes, 1, l.output + index + 5);
}
}
}
@@ -228,6 +231,45 @@
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)
+{
+ int i,j,n;
+ float *predictions = l.output;
+ //int per_cell = 5*num+classes;
+ for (i = 0; i < l.w*l.h; ++i){
+ int row = i / l.w;
+ int col = i % l.w;
+ for(n = 0; n < l.n; ++n){
+ int index = i*l.n + n;
+ int p_index = index * (l.classes + 5) + 4;
+ float scale = predictions[p_index];
+ int box_index = index * (l.classes + 5);
+ boxes[index].x = (predictions[box_index + 0] + col + .5) / l.w * w;
+ boxes[index].y = (predictions[box_index + 1] + row + .5) / l.h * h;
+ if(0){
+ boxes[index].x = (logistic_activate(predictions[box_index + 0]) + col) / l.w * w;
+ boxes[index].y = (logistic_activate(predictions[box_index + 1]) + row) / l.h * h;
+ }
+ boxes[index].w = pow(logistic_activate(predictions[box_index + 2]), (l.sqrt?2:1)) * w;
+ boxes[index].h = pow(logistic_activate(predictions[box_index + 3]), (l.sqrt?2:1)) * h;
+ if(1){
+ boxes[index].x = ((col + .5)/l.w + predictions[box_index + 0] * .5) * w;
+ boxes[index].y = ((row + .5)/l.h + predictions[box_index + 1] * .5) * h;
+ boxes[index].w = (exp(predictions[box_index + 2]) * .5) * w;
+ boxes[index].h = (exp(predictions[box_index + 3]) * .5) * h;
+ }
+ for(j = 0; j < l.classes; ++j){
+ int class_index = index * (l.classes + 5) + 5;
+ 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_region_layer_gpu(const region_layer l, network_state state)
--
Gitblit v1.10.0