darknet  v3
col2im.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <math.h>
3 void col2im_add_pixel(float *im, int height, int width, int channels,
4  int row, int col, int channel, int pad, float val)
5 {
6  row -= pad;
7  col -= pad;
8 
9  if (row < 0 || col < 0 ||
10  row >= height || col >= width) return;
11  im[col + width*(row + height*channel)] += val;
12 }
13 //This one might be too, can't remember.
14 void col2im_cpu(float* data_col,
15  int channels, int height, int width,
16  int ksize, int stride, int pad, float* data_im)
17 {
18  int c,h,w;
19  int height_col = (height + 2*pad - ksize) / stride + 1;
20  int width_col = (width + 2*pad - ksize) / stride + 1;
21 
22  int channels_col = channels * ksize * ksize;
23  for (c = 0; c < channels_col; ++c) {
24  int w_offset = c % ksize;
25  int h_offset = (c / ksize) % ksize;
26  int c_im = c / ksize / ksize;
27  for (h = 0; h < height_col; ++h) {
28  for (w = 0; w < width_col; ++w) {
29  int im_row = h_offset + h * stride;
30  int im_col = w_offset + w * stride;
31  int col_index = (c * height_col + h) * width_col + w;
32  double val = data_col[col_index];
33  col2im_add_pixel(data_im, height, width, channels,
34  im_row, im_col, c_im, pad, val);
35  }
36  }
37  }
38 }
39 
void col2im_add_pixel(float *im, int height, int width, int channels, int row, int col, int channel, int pad, float val)
Definition: col2im.c:3
void col2im_cpu(float *data_col, int channels, int height, int width, int ksize, int stride, int pad, float *data_im)
Definition: col2im.c:14