From 1106f5325b8bd3dc4b5fe776d8abecbe3879b9d2 Mon Sep 17 00:00:00 2001
From: Alexey <AlexeyAB@users.noreply.github.com>
Date: Sun, 18 Feb 2018 16:44:58 +0000
Subject: [PATCH] Update Readme.md
---
src/region_layer.c | 36 +++++++++++++++++++++---------------
1 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/region_layer.c b/src/region_layer.c
index 5e8387d..d48e8d0 100644
--- a/src/region_layer.c
+++ b/src/region_layer.c
@@ -11,7 +11,7 @@
#define DOABS 1
-region_layer make_region_layer(int batch, int w, int h, int n, int classes, int coords)
+region_layer make_region_layer(int batch, int w, int h, int n, int classes, int coords, int max_boxes)
{
region_layer l = {0};
l.type = REGION;
@@ -27,7 +27,8 @@
l.bias_updates = calloc(n*2, sizeof(float));
l.outputs = h*w*n*(classes + coords + 1);
l.inputs = l.outputs;
- l.truths = 30*(5);
+ l.max_boxes = max_boxes;
+ l.truths = max_boxes*(5);
l.delta = calloc(batch*l.outputs, sizeof(float));
l.output = calloc(batch*l.outputs, sizeof(float));
int i;
@@ -44,7 +45,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;
@@ -169,7 +170,7 @@
for (b = 0; b < l.batch; ++b){
for(i = 0; i < l.h*l.w*l.n; ++i){
int index = size*i + b*l.outputs;
- softmax(l.output + index + 5, l.classes, 1, l.output + index + 5);
+ softmax(l.output + index + 5, l.classes, 1, l.output + index + 5, 1);
}
}
}
@@ -187,7 +188,7 @@
for (b = 0; b < l.batch; ++b) {
if(l.softmax_tree){
int onlyclass = 0;
- for(t = 0; t < 30; ++t){
+ for(t = 0; t < l.max_boxes; ++t){
box truth = float_to_box(state.truth + t*5 + b*l.truths);
if(!truth.x) break;
int class = state.truth[t*5 + b*l.truths + 4];
@@ -196,7 +197,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;
@@ -218,7 +220,7 @@
box pred = get_region_box(l.output, l.biases, n, index, i, j, l.w, l.h);
float best_iou = 0;
int best_class = -1;
- for(t = 0; t < 30; ++t){
+ for(t = 0; t < l.max_boxes; ++t){
box truth = float_to_box(state.truth + t*5 + b*l.truths);
if(!truth.x) break;
float iou = box_iou(pred, truth);
@@ -255,7 +257,7 @@
}
}
}
- for(t = 0; t < 30; ++t){
+ for(t = 0; t < l.max_boxes; ++t){
box truth = float_to_box(state.truth + t*5 + b*l.truths);
if(!truth.x) break;
@@ -324,7 +326,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 +350,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 +364,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 +410,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 +420,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