From 9802287b5890d9b2cc250adba1b9810657a95c9c Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 18 Dec 2015 23:55:58 +0000
Subject: [PATCH] some fixes
---
src/convolutional_layer.c | 39 +++++++++++++++++++++++++--------------
1 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/src/convolutional_layer.c b/src/convolutional_layer.c
index b9fd3c9..e97b00d 100644
--- a/src/convolutional_layer.c
+++ b/src/convolutional_layer.c
@@ -86,9 +86,8 @@
}
l.mean = calloc(n, sizeof(float));
- l.spatial_mean = calloc(n*l.batch, sizeof(float));
-
l.variance = calloc(n, sizeof(float));
+
l.rolling_mean = calloc(n, sizeof(float));
l.rolling_variance = calloc(n, sizeof(float));
}
@@ -114,12 +113,6 @@
l.rolling_mean_gpu = cuda_make_array(l.mean, n);
l.rolling_variance_gpu = cuda_make_array(l.variance, n);
- l.spatial_mean_gpu = cuda_make_array(l.spatial_mean, n*l.batch);
- l.spatial_variance_gpu = cuda_make_array(l.spatial_mean, n*l.batch);
-
- l.spatial_mean_delta_gpu = cuda_make_array(l.spatial_mean, n*l.batch);
- l.spatial_variance_delta_gpu = cuda_make_array(l.spatial_mean, n*l.batch);
-
l.mean_delta_gpu = cuda_make_array(l.mean, n);
l.variance_delta_gpu = cuda_make_array(l.variance, n);
@@ -201,13 +194,25 @@
#endif
}
-void bias_output(float *output, float *biases, int batch, int n, int size)
+void add_bias(float *output, float *biases, int batch, int n, int size)
{
int i,j,b;
for(b = 0; b < batch; ++b){
for(i = 0; i < n; ++i){
for(j = 0; j < size; ++j){
- output[(b*n + i)*size + j] = biases[i];
+ output[(b*n + i)*size + j] += biases[i];
+ }
+ }
+ }
+}
+
+void scale_bias(float *output, float *scales, int batch, int n, int size)
+{
+ int i,j,b;
+ for(b = 0; b < batch; ++b){
+ for(i = 0; i < n; ++i){
+ for(j = 0; j < size; ++j){
+ output[(b*n + i)*size + j] *= scales[i];
}
}
}
@@ -229,7 +234,7 @@
int out_w = convolutional_out_width(l);
int i;
- bias_output(l.output, l.biases, l.batch, l.n, out_h*out_w);
+ fill_cpu(l.outputs*l.batch, 0, l.output, 1);
int m = l.n;
int k = l.size*l.size*l.c;
@@ -248,10 +253,16 @@
}
if(l.batch_normalize){
- mean_cpu(l.output, l.batch, l.n, l.out_h*l.out_w, l.mean);
- variance_cpu(l.output, l.mean, l.batch, l.n, l.out_h*l.out_w, l.variance);
- normalize_cpu(l.output, l.mean, l.variance, l.batch, l.n, l.out_h*l.out_w);
+ if(state.train){
+ mean_cpu(l.output, l.batch, l.n, l.out_h*l.out_w, l.mean);
+ variance_cpu(l.output, l.mean, l.batch, l.n, l.out_h*l.out_w, l.variance);
+ normalize_cpu(l.output, l.mean, l.variance, l.batch, l.n, l.out_h*l.out_w);
+ } else {
+ normalize_cpu(l.output, l.rolling_mean, l.rolling_variance, l.batch, l.n, l.out_h*l.out_w);
+ }
+ scale_bias(l.output, l.scales, l.batch, l.n, out_h*out_w);
}
+ add_bias(l.output, l.biases, l.batch, l.n, out_h*out_w);
activate_array(l.output, m*n*l.batch, l.activation);
}
--
Gitblit v1.10.0