这里,我是将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 ;
}

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

Caffe中im2col的实现解析的更多相关文章

  1. caffe代码阅读10:Caffe中卷积的实现细节(涉及到BaseConvolutionLayer、ConvolutionLayer、im2col等)-2016.4.3

    一. 卷积层的作用简单介绍 卷积层是深度神经网络中的一个重要的层,该层实现了局部感受野.通过这样的局部感受野,能够有效地减少參数的数目. 我们将结合caffe来解说详细是怎样实现卷积层的前传和反传的. ...

  2. caffe中ConvolutionLayer的前向和反向传播解析及源码阅读

    一.前向传播 在caffe中,卷积层做卷积的过程被转化成了由卷积核的参数组成的权重矩阵weights(简记为W)和feature map中的元素组成的输入矩阵(简记为Cin)的矩阵乘积W * Cin. ...

  3. CAFFE中训练与使用阶段网络设计的不同

    神经网络中,我们通过最小化神经网络来训练网络,所以在训练时最后一层是损失函数层(LOSS), 在测试时我们通过准确率来评价该网络的优劣,因此最后一层是准确率层(ACCURACY). 但是当我们真正要使 ...

  4. caffe 中base_lr、weight_decay、lr_mult、decay_mult代表什么意思?

    在机器学习或者模式识别中,会出现overfitting,而当网络逐渐overfitting时网络权值逐渐变大,因此,为了避免出现overfitting,会给误差函数添加一个惩罚项,常用的惩罚项是所有权 ...

  5. caffe 中 plot accuracy和loss, 并画出网络结构图

    plot accuracy + loss 详情可见:http://www.2cto.com/kf/201612/575739.html 1. caffe保存训练输出到log 并绘制accuracy l ...

  6. .NET Core中的认证管理解析

    .NET Core中的认证管理解析 0x00 问题来源 在新建.NET Core的Web项目时选择“使用个人用户账户”就可以创建一个带有用户和权限管理的项目,已经准备好了用户注册.登录等很多页面,也可 ...

  7. OS中atomic的实现解析

    OS中atomic的实现解析 转自:http://my.oschina.net/majiage/blog/267409    摘要 atomic属性线程安全,会增加一定开销,但有些时候必须自定义ato ...

  8. AngularJS中的指令全面解析(转载)

    说到AngularJS,我们首先想到的大概也就是双向数据绑定和指令系统了,这两者也是AngularJS中最为吸引人的地方.双向数据绑定呢,感觉没什么好说的,那么今天我们就来简单的讨论下AngularJ ...

  9. Java中的static关键字解析

    Java中的static关键字解析 static关键字是很多朋友在编写代码和阅读代码时碰到的比较难以理解的一个关键字,也是各大公司的面试官喜欢在面试时问到的知识点之一.下面就先讲述一下static关键 ...

随机推荐

  1. 后端脚手架搭建--SSM(一)开篇

    一.絮叨 一直在计划自己搭建一个后台的管理系统脚手架,也已经开始着手做了,但是做的过程中一直出现混乱的状态.在前端技术选型的时候觉得Vue不错,然后去学了一段时间的Vue,准备拿来在项目里面用.然后又 ...

  2. Springboot获取resource的路径

    1.获取resource目录下的template路径 String path = Thread.currentThread().getContextClassLoader().getResource( ...

  3. Unity和Mef的比较

    1:Mef和Untiy都支持依赖注入 2:Mef支持插件的机制 3:Mef在写法上更简单灵活 4:Mef在宏观上比Unity更加庞大 5:Mef不支持Aop的切入拦截,Unity支持

  4. httpClient模仿Basic Auth

    httpclient代码调用如下: @GetMapping("loginTest") public String httpClientWithBasicAuth() { Strin ...

  5. 解决 JDK1.7 不支持 VCenter 6.7 的问题(涉及到Https TLS1.2协议)

    解决 JDK1.7 不支持 VCenter 6.7 的问题 问题描述 原项目工程是使用JDK 1.7,可以连接 5.X版本和 6.0版本的 VCenter资源池. 但是,现在VCenter已经升到 6 ...

  6. Win10+GPU版Pytorch1.1安装

    环境配置篇 安装cuda 更新nvidia驱动 打开GeForce Game Ready Driver或在 GeForce Experience中下载符合自己gpu的程序. 选择cuda 打开nvid ...

  7. 嵌入式【杂记--手机芯片与pc】

    手机.身边的移动设备大多数是嵌入式计算机,pc也是计算机,只是功耗上很大. 手机所采用的大多数芯片是英国ARM公司的架构coretom A系列 core, Intel公司采用自己的架构设计的芯片适用于 ...

  8. yum安装etcd集群

       前一篇文章介绍了如何yum安装简单的kubernetes集群,其中etcd是单点部署.本篇我们来搭建etcd集群,方便日后搭建kubernetes HA集群架构. 1,环境配置说明 etcd1 ...

  9. python基础知识(字符串)

    定义字符串 ' '单引号 " "双引号  只能用于单行 '" '"三引号  可以用于多行 拼接字符串使用  +号链接 字符串只能链接字符串其他类型字符串需要用s ...

  10. Linux批量文件管理

    Linux批量文件管理   实验目标: 通过本实验掌握批量建立.移动.复制文件或目录的操作,也可以作为后续shell编程的基础. 实验步骤: 1.现在有十台终端机器,要为每台机器建立3个文件,总共要建 ...