| | |
| | | #include "maxpool_layer.h" |
| | | #include "cuda.h" |
| | | #include <stdio.h> |
| | | |
| | | image get_maxpool_image(maxpool_layer layer) |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | 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; |