Joseph Redmon
2015-02-04 bfffadc75502cadb5d05909435a2167db5204325
src/maxpool_layer.c
@@ -1,4 +1,5 @@
#include "maxpool_layer.h"
#include "cuda.h"
#include <stdio.h>
image get_maxpool_image(maxpool_layer layer)
@@ -27,9 +28,15 @@
    layer->c = c;
    layer->size = size;
    layer->stride = stride;
    layer->indexes = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(int));
    layer->output = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(float));
    layer->delta = calloc(((h-1)/stride+1) * ((w-1)/stride+1) * c*batch, sizeof(float));
    int output_size = ((h-1)/stride+1) * ((w-1)/stride+1) * c * batch;
    layer->indexes = calloc(output_size, sizeof(int));
    layer->output =  calloc(output_size, sizeof(float));
    layer->delta =   calloc(output_size, sizeof(float));
    #ifdef GPU
    layer->indexes_gpu = cuda_make_int_array(output_size);
    layer->output_gpu  = cuda_make_array(layer->output, output_size);
    layer->delta_gpu   = cuda_make_array(layer->delta, output_size);
    #endif
    return layer;
}
@@ -66,7 +73,7 @@
                            int index = cur_w + layer.w*(cur_h + layer.h*(k + b*layer.c));
                            int valid = (cur_h >= 0 && cur_h < layer.h &&
                                         cur_w >= 0 && cur_w < layer.w);
                            float val = (valid != 0) ? input[index] : -INFINITY;
                            float val = (valid != 0) ? input[index] : -FLT_MAX;
                            max_i = (val > max) ? index : max_i;
                            max   = (val > max) ? val   : max;
                        }
@@ -79,7 +86,7 @@
    }
}
void backward_maxpool_layer(const maxpool_layer layer, float *input, float *delta)
void backward_maxpool_layer(const maxpool_layer layer, float *delta)
{
    int i;
    int h = (layer.h-1)/layer.stride + 1;