caffe——常用层及其参数

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:500
weight_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。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值