caffe——常用层及其参数

来源:互联网 发布:数据一致性数据治理 编辑:程序博客网 时间:2024/06/05 16:54

caffe——常用层及其参数
我们常用的层包括:softmax_loss层,inner_Product层,accuracy层,reshape层和dropout层。
1 softmax_loss
softmax_loss层和softmax计算大致相同。softmax是一个分类器,计算的是类别的概率。
这里写图片描述
如果用户最终想得到各个类别的概率似然值,这时候只需要一个Softmax层,不需要softmax-Loss操作,如果用户已经得到某种概率似然值,然后要做最大似燃估计,则只需要后面的softmax_loss,而不需要Softmax操作。因此提供来两个不同的Layer结构,更加灵活。
softmax-loss layer:输出loss值

layer{name:"loss"type:"SoftmaxWithloss"bottom:"ip1"bottom:"label"top:"loss"}

softmax layer:输出似然值

layer{bottom:"cls3_fc"top:"prob"name:"prob"type:"Softmax"}

2 ineer product
全连接层:输入一个向量,输出也是一个简单的向量
输入:n*c0*h*w
输出:n*c1*1*1
全连接层类型:innerProduct
lr_mult:学习率的系数,最终的需西率是这个数乘以solver.prototxt配置文件中的base_lr。如果有两个lr_mult.则第一个表示权值学习率,第二个表示偏置学习率。一般偏置学习率是权值学习率的两倍。
必须设置的参数:
num_output:过滤器(filters)的个数
其他参数:
weight_filter:权值初始化。默认全为0,很多情况用“xavier”进行初始化,也可设置为“gaussian”。
bias_filler:偏置项初始化,一般为”constant”,值全为0
bias_term:是否开启偏置项,默认开启

layer{name:"ip1"type:"InnerProduct"bottom:"pool2"top:"ip1"param{lr_mult:1}param{lr_mult:2}inner_product_param{num_output:500weight_filler{typr:"xavier"}bias_filler{type:"constant"        }    }}

3 accuracy
输出分类精确度,只有test阶段才有,因此需要加入include参数
层类型:Accuracy

layer{name:"accuracy"type:"Accuracy"bottom:"label"bottom:"ip2"top:"accuracy"include{phase:TEST    }}

4 reshape
在不改变数据的情况下,改变输入的维度
层类型:Reshape

layer{name:"reshape"type:"Reshape"bottom:"input"top:"output"reshape_param{    shape{        dim:0 #copy the dimension from below        dim:2        dim:3        dim:-1 #infer it from the other dimension        }    }}

有一组可选参数shape,用于指定blob数据的各维的值(blob是一个四维数据: n*c*w*h)
dim:0 表示维度不变,即输入和输出是相同的维度
dim:2 或dim:3表示将原来维度变为2 或3
dim:-1 表示由系统自动计算维度。数据总量不变,系统根据blob的数据的其他三维来计算当前维度值 。

5 Dropout
dropout是一个防止过拟合的trick。可以随机让某些隐含层节点的权重不工作

layer{name:"drop7"type:"Dropout"bottom:"fc7-conv"top:"fc7-conv"dropout{dropout_param:0.5    }}

只需设置一个dropout_ratio。

原创粉丝点击