You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. if (row < 0 || col < 0 ||
  9. row >= height || col >= width) return;
  10. im[col + width*(row + height*channel)] += val;
  11. }
  12. //This one might be too, can't remember.
  13. void col2im_cpu(float* data_col,
  14. int channels, int height, int width,
  15. int ksize, int stride, int pad, float* data_im)
  16. {
  17. int c,h,w;
  18. int height_col = (height + 2*pad - ksize) / stride + 1;
  19. int width_col = (width + 2*pad - ksize) / stride + 1;
  20. int channels_col = channels * ksize * ksize;
  21. for (c = 0; c < channels_col; ++c) {
  22. int w_offset = c % ksize;
  23. int h_offset = (c / ksize) % ksize;
  24. int c_im = c / ksize / ksize;
  25. for (h = 0; h < height_col; ++h) {
  26. for (w = 0; w < width_col; ++w) {
  27. int im_row = h_offset + h * stride;
  28. int im_col = w_offset + w * stride;
  29. int col_index = (c * height_col + h) * width_col + w;
  30. float val = data_col[col_index];
  31. col2im_add_pixel(data_im, height, width, channels,
  32. im_row, im_col, c_im, pad, val);
  33. }
  34. }
  35. }
  36. }