From 0305fb4d99cf1efc7d4aa4d2ee2d65d54500d437 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Thu, 26 Nov 2015 19:48:01 +0000
Subject: [PATCH] Some changes

---
 src/maxpool_layer.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/maxpool_layer.c b/src/maxpool_layer.c
index c7739f1..2017627 100644
--- a/src/maxpool_layer.c
+++ b/src/maxpool_layer.c
@@ -4,16 +4,16 @@
 
 image get_maxpool_image(maxpool_layer l)
 {
-    int h = (l.h-1)/l.stride + 1;
-    int w = (l.w-1)/l.stride + 1;
+    int h = l.out_h;
+    int w = l.out_w;
     int c = l.c;
     return float_to_image(w,h,c,l.output);
 }
 
 image get_maxpool_delta(maxpool_layer l)
 {
-    int h = (l.h-1)/l.stride + 1;
-    int w = (l.w-1)/l.stride + 1;
+    int h = l.out_h;
+    int w = l.out_w;
     int c = l.c;
     return float_to_image(w,h,c,l.delta);
 }
@@ -27,14 +27,14 @@
     l.h = h;
     l.w = w;
     l.c = c;
-    l.out_h = h;
-    l.out_w = w;
+    l.out_w = (w-1)/stride + 1;
+    l.out_h = (h-1)/stride + 1;
     l.out_c = c;
     l.outputs = l.out_h * l.out_w * l.out_c;
-    l.inputs = l.outputs;
+    l.inputs = h*w*c;
     l.size = size;
     l.stride = stride;
-    int output_size = ((h-1)/stride+1) * ((w-1)/stride+1) * c * batch;
+    int output_size = l.out_h * l.out_w * l.out_c * batch;
     l.indexes = calloc(output_size, sizeof(int));
     l.output =  calloc(output_size, sizeof(float));
     l.delta =   calloc(output_size, sizeof(float));
@@ -46,11 +46,18 @@
     return l;
 }
 
-void resize_maxpool_layer(maxpool_layer *l, int h, int w)
+void resize_maxpool_layer(maxpool_layer *l, int w, int h)
 {
+    int stride = l->stride;
     l->h = h;
     l->w = w;
-    int output_size = ((h-1)/l->stride+1) * ((w-1)/l->stride+1) * l->c * l->batch;
+
+    l->out_w = (w-1)/stride + 1;
+    l->out_h = (h-1)/stride + 1;
+    l->outputs = l->out_w * l->out_h * l->c;
+    int output_size = l->outputs * l->batch;
+
+    l->indexes = realloc(l->indexes, output_size * sizeof(int));
     l->output = realloc(l->output, output_size * sizeof(float));
     l->delta = realloc(l->delta, output_size * sizeof(float));
 
@@ -60,7 +67,7 @@
     cuda_free(l->delta_gpu);
     l->indexes_gpu = cuda_make_int_array(output_size);
     l->output_gpu  = cuda_make_array(l->output, output_size);
-    l->delta_gpu   = cuda_make_array(l->delta, output_size);
+    l->delta_gpu   = cuda_make_array(l->delta,  output_size);
     #endif
 }
 
@@ -107,7 +114,6 @@
     int h = (l.h-1)/l.stride + 1;
     int w = (l.w-1)/l.stride + 1;
     int c = l.c;
-    memset(state.delta, 0, l.batch*l.h*l.w*l.c*sizeof(float));
     for(i = 0; i < h*w*c*l.batch; ++i){
         int index = l.indexes[i];
         state.delta[index] += l.delta[i];

--
Gitblit v1.10.0