30 l.
out_w = (w + padding - size)/stride + 1;
31 l.
out_h = (h + padding - size)/stride + 1;
38 l.
indexes = calloc(output_size,
sizeof(
int));
39 l.
output = calloc(output_size,
sizeof(
float));
40 l.
delta = calloc(output_size,
sizeof(
float));
46 l.indexes_gpu = cuda_make_int_array(0, output_size);
47 l.output_gpu = cuda_make_array(l.
output, output_size);
48 l.delta_gpu = cuda_make_array(l.
delta, output_size);
50 fprintf(stderr,
"max %d x %d / %d %4d x%4d x%4d -> %4d x%4d x%4d\n", size, size, stride, w, h, c, l.
out_w, l.
out_h, l.
out_c);
66 l->
output = realloc(l->
output, output_size *
sizeof(
float));
67 l->
delta = realloc(l->
delta, output_size *
sizeof(
float));
70 cuda_free((
float *)l->indexes_gpu);
71 cuda_free(l->output_gpu);
72 cuda_free(l->delta_gpu);
73 l->indexes_gpu = cuda_make_int_array(0, output_size);
74 l->output_gpu = cuda_make_array(l->
output, output_size);
75 l->delta_gpu = cuda_make_array(l->
delta, output_size);
82 int w_offset = -l.
pad/2;
83 int h_offset = -l.
pad/2;
89 for(b = 0; b < l.
batch; ++b){
90 for(k = 0; k < c; ++k){
91 for(i = 0; i < h; ++i){
92 for(j = 0; j < w; ++j){
93 int out_index = j + w*(i + h*(k + c*b));
96 for(n = 0; n < l.
size; ++n){
97 for(m = 0; m < l.
size; ++m){
98 int cur_h = h_offset + i*l.
stride + n;
99 int cur_w = w_offset + j*l.
stride + m;
100 int index = cur_w + l.
w*(cur_h + l.
h*(k + b*l.
c));
101 int valid = (cur_h >= 0 && cur_h < l.
h &&
102 cur_w >= 0 && cur_w < l.
w);
103 float val = (valid != 0) ? net.
input[index] : -FLT_MAX;
104 max_i = (val > max) ? index : max_i;
105 max = (val > max) ? val : max;
108 l.
output[out_index] = max;
122 for(i = 0; i < h*w*c*l.
batch; ++i){
void(* forward_gpu)(struct layer, struct network)
void(* backward_gpu)(struct layer, struct network)
void(* forward)(struct layer, struct network)
image float_to_image(int w, int h, int c, float *data)
void backward_maxpool_layer(const maxpool_layer l, network net)
void resize_maxpool_layer(maxpool_layer *l, int w, int h)
void(* backward)(struct layer, struct network)
image get_maxpool_image(maxpool_layer l)
void forward_maxpool_layer_gpu(maxpool_layer layer, network net)
image get_maxpool_delta(maxpool_layer l)
void forward_maxpool_layer(const maxpool_layer l, network net)
void backward_maxpool_layer_gpu(maxpool_layer layer, network net)
maxpool_layer make_maxpool_layer(int batch, int h, int w, int c, int size, int stride, int padding)