这里,我是将Caffe中im2col的解析过程直接拉了出来,使用C++进行了输出,方便理解。代码如下:

 #include<iostream>

 using namespace std;

 bool is_a_ge_zero_and_a_lt_b(int a,int b)
{
if(a>= && a <b) return true;
return false;
} void im2col_cpu(const float* data_im, const int channels,
const int height, const int width, const int kernel_h, const int kernel_w,
const int pad_h, const int pad_w,
const int stride_h, const int stride_w,
const int dilation_h, const int dilation_w,
float* data_col) {
const int output_h = (height + * pad_h -
(dilation_h * (kernel_h - ) + )) / stride_h + ;
const int output_w = (width + * pad_w -
(dilation_w * (kernel_w - ) + )) / stride_w + ;
const int channel_size = height * width;
for (int channel = channels; channel--; data_im += channel_size) {
for (int kernel_row = ; kernel_row < kernel_h; kernel_row++) {
for (int kernel_col = ; kernel_col < kernel_w; kernel_col++) {
int input_row = -pad_h + kernel_row * dilation_h;
for (int output_rows = output_h; output_rows; output_rows--) {
if (!is_a_ge_zero_and_a_lt_b(input_row, height)) {
for (int output_cols = output_w; output_cols; output_cols--) {
*(data_col++) = ;
}
} else {
int input_col = -pad_w + kernel_col * dilation_w;
for (int output_col = output_w; output_col; output_col--) {
if (is_a_ge_zero_and_a_lt_b(input_col, width)) {
*(data_col++) = data_im[input_row * width + input_col];
} else {
*(data_col++) = ;
}
input_col += stride_w;
}
}
input_row += stride_h;
}
}
}
}
} int main()
{
float* data_im;
int height=;
int width=;
int kernel_h=;
int kernel_w=;
int pad_h=;
int pad_w=;
int stride_h=;
int stride_w=;
int dilation_h=;
int dilation_w=;
float* data_col;
int channels =;
const int output_h = (height + * pad_h -
(dilation_h * (kernel_h - ) + )) / stride_h + ;
const int output_w = (width + * pad_w -
(dilation_w * (kernel_w - ) + )) / stride_w + ;
data_im = new float[channels*height*width];
data_col = new float[channels*output_h*output_w*kernel_h*kernel_w]; //init input image data
for(int m=;m<channels;++m)
{
for(int i=;i<height;++i)
{
for(int j=;j<width;++j)
{
data_im[m*width*height+i*width+j] = m*width*height+ i*width +j;
cout <<data_im[m*width*height+i*width+j] <<' ';
}
cout <<endl;
}
} im2col_cpu(data_im, channels,
height,width, kernel_h, kernel_w,
pad_h, pad_w,
stride_h, stride_w,
dilation_h, dilation_w,
data_col);
cout <<channels<<endl;
cout <<output_h<<endl;
cout <<output_w<<endl;
cout <<kernel_h<<endl;
cout <<kernel_w<<endl;
// cout <<"error"<<endl;
for(int i=;i<kernel_w*kernel_h*channels;++i)
{
for(int j=;j<output_w*output_h;++j)
{
cout <<data_col[i*output_w*output_h+j]<<' ';
}
cout <<endl;
} return ;
}

多通道卷积的图像别人已经给过很多了,大家可以搜到的基本都来自于一篇。这里附上一个我自己的理解过程,和程序的输出是完全一致的

最新文章

  1. Mybatis-mapper-xml-基础
  2. JE22环境安装配置(JDK/ANT/TOMCAT/ECLIPSE)
  3. jQuery插件编写规范
  4. 【C++ STL编程】queue小例子
  5. .net微信公众号开发——基础接口
  6. c# double保留2位小数
  7. hihocoder-1391&amp;&amp;北京网赛09 Countries(优先队列)
  8. bitmap size exceeds VM budget
  9. HTML基本操作
  10. 在C#中我们能调用一个类的私有方法吗
  11. 【PNG格式中文详解】
  12. winform 窗体最大化 分类: WinForm 2014-07-17 15:57 215人阅读 评论(0) 收藏
  13. 不使用TNS直连数据库的三种方式
  14. linux网口绑定笔记-bind
  15. 【Python 20】BMR计算器4.0(异常处理)
  16. git 创建项目
  17. Java数据结构与算法结构图
  18. TCP 粘包问题浅析及其解决方案
  19. 每天一个linux命令(9):touch
  20. hdu 1711( 模式串T在主串S中首次出现的位置)

热门文章

  1. openLdap安装教程
  2. .NetCore接入Log4Net
  3. centos升级glibc2.23编译安装
  4. web容器启动加载WebApplicationContext和初始化DispatcherServlet
  5. SqlServer:SqlServer(sql,游标,定时作业,行转列,列转行,公用表达式递归,merge合并)
  6. 小程序请求豆瓣API报403解决方法
  7. netcore程序部署 ubuntu 16.0.4 报错 The type initializer for &#39;System.Net.Http.CurlHandler&#39;的解决方案
  8. sqlalchemy一对一关系映射
  9. 小菜鸟之oracle数据字典
  10. tp5.1中redis使用