Caffe下卷积神经网络中的一些特殊层(caffe不同类型层的介绍)

Batch Normalization
意义: 网络训练时,用来加速收敛速度
提醒:
已经将BN集成为一个layer了,使用时需要和scale层一起使用
训练的时候,将BN层的use_global_stats设置为false; 测试的时候将use_global_stats设置为true,不然训练的时候会报“NAN”或者模型不收敛 – 师兄的经验,我还没试验过
用法: 详见 残差神经网络的使用
Dropout
意义: 防止模型过拟合;训练模型时,随机让网络某些隐含层节点的权重不工作(不工作的那些节点可以暂时认为不是网络结构的一部分,但是它的权重得保留下来,只是暂时不更新而已,因为下次样本输入时它可能又得工作了)
用法:

layer { 
name: “drop7” 
type: “Dropout” 
bottom: “fc7-conv” 
top: “fc7-conv” 
dropout_param { 
dropout_ratio: 0.5 
} 
}

ReLU
意义: 激活函数的一种;对于给定的一个输入值x,如果x > 0,ReLU层的输出为x,如果x < 0,ReLU层的输出为0。
提醒: 可选参数negative_slope,此参数使得x < 0时,ReLU层的输出为negative_slope * x;目前已经有了ReLU的进化版 – PReLU
用法:

layer { 
name: “relu1” 
type: “ReLU” 
bottom: “conv1” 
top: “conv1” 
relu_param{ 
negative_slope: [默认:0] 
} 
}

PReLU
意义: ReLu的进化版;。
提醒: 在负半轴的输出乘以一个系数,而这个系数是可学习的(你可以为其指定学习率),其中value是系数的初始值,channel_shared指定是否在各个通道间共享这个系数。 据说有的实验更快更好地收敛,但有的实验准确率却有所下降 - 具体效果还是得以具体实验为准(自己没有用过,不加评论
-用法:

layer { 
name: “relu1” 
type: “PReLU” 
bottom: “conv1” 
top: “conv1” 
param { 
lr_mult: 1 
decay_mult: 0 
} 
prelu_param { 
filler: { 
value: 0.33 #: 默认为0.25 
} 
channel_shared: false 
} 
}

Split
意义: 将一份blob复制为n份
提醒: caffe会隐式地做这个操作,我也不知道什么时候会显式地用到这个操作,先搁这儿吧(没实际用过这个操作,所以下面的用法不一定对)
用法:

layer { 
name: “split” 
type: “split” 
bottom: “rois” 
top: “rois1” 
top: “rois2” 
}

Reshape
意义: 改变blob的维度,而不改变其自身的数据
提醒: 每个blob为4维,故有4个dim参数【0代表不改变维度的值,-1代表由caffe计算出值,正数代表将维度更改为对应的值】

layer { 
name: “reshape” 
type: “Reshape” 
bottom: “conv1” 
top: “conv1” 
reshape_param { 
shape { 
dim: 0 # copy the dimension from below 
dim: 2 
dim: 3 
dim: -1 # infer it from the other dimensions 
} 
} 
} 

注: 若1个参数分别为 dim:1 dim:3 dim:2 dim:-1的reshape层,输入为1个维度为1*2*3*4的blob,那么输出的blob维度为1*3*2*4(其中4是由caffe计算而来的)

InnerProduct
意义: 将输入数据以简单的向量形式进行处理,并且输出一个简单的向量;简单来说,这是一个卷积操作,只不过卷积核尺寸和feature map相同,故输出向量大小为1*1
缺点:使用包含全连接层的模型(如AlexNet)必须使用固定大小的输入,有时这是非常不合理的,因为必须对输入图片进行变形。
提醒:
必要参数:
num_output (c_o):滤波器数量
强烈建议参数:
weight_filler:滤波器的初始分布和分布参数。
可选参数:
bias_filler:[默认: type: ‘constant’ value: 0]
bias_term:[默认:true] 指定是否在滤波器输出之后学习并应用附加的偏置。
用法:

layer { 
name: “fc8” 
type: “InnerProduct” 
bottom: “fc7” 
top: “fc8”

param { # learning rate and decay multipliers for the weights 
lr_mult: 1 decay_mult: 1 
}

param { # learning rate and decay multipliers for the biases 
lr_mult: 2 decay_mult: 0 
}

inner_product_param { 
num_output: 1000

weight_filler { 
type: “xavier” 
std: 0.01 
}

bias_filler { 
type: “constant” 
value: 0 
} 
} 
} 

注: 比如上面层的输入为 n * c_i * h_i * w_i,那么输入为 n * 1000 * 1 * 1

Crop

意义:输入两个blob,将bottom[0] 按照bottom[1]的尺寸进行剪裁
提醒:
axis=0,1,2,3分别表示为N,C,H,W;默认axis等于2,即默认从H开始裁剪(裁剪H和W);可以只设置1个,也可以为每个dimension分别设置
offset表示裁剪时的偏移量(如果还是不太清楚的话,戳这儿
用法:

layer { 
type: “Crop” 
name: ‘crop’ 
bottom: ‘score-dsn1-up’ 
bottom: ‘data’ 
top: ‘upscore-dsn1’ 
crop_param { 
axis: 2 
offset: 5 
} 
}

连结 Concatenation

层类型: Concat
? CPU 实现代码: ./src/caffe/layers/concat_layer.cpp
? CUDA GPU 实现代码: ./src/caffe/layers/concat_layer.cu
? 参数 (ConcatParameter concat_param)
? 可选
axis [default 1]: 0 表示沿着样本个数的维度(num)串联, 1 表示沿着通道维度
(channels)串联
输入
n_i * c_i * h * w 对于第 i 个输入 blob, i 的取值为{1,2,…,K}
? 输出
1. if axis = 0: (n_1 + n_2 + … + n_K) * c_1 * h * w, 所有输入 blob 在通道上的维度
c_i 需相同;
2. if axis = 1: n_1 * (c_1 + c_2 + … + c_K) * h * w, 所有输入 blob 在样本个数上的
维度 n_i 需相同。
Concat 层用来将多个输入 blob 连结成一个 blob 输出

 layer { 
  name: "concat" 
  bottom: "in1" 
  bottom: "in2" 
  top: "out" 
  type: "Concat" 
  concat_param { 
    axis: 1 
  } 
} 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值