从零开始,一步一步学习caffe的使用,期间贯穿深度学习和调参的相关知识!
layers {
bottom: "cls3_fc"
top: "prob"
name: "prob"
type: "softmax"
}
公式如下所示:
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip1"
bottom: "label"
top: "loss"
loss_param{
ignore_label:0
normalize: 1
normalization: FULL
}
}
公式如下所示:
loss_param 说明:
enum NormalizationMode {
// Divide by the number of examples in the batch times spatial dimensions.
// Outputs that receive the ignore label will NOT be ignored in computing the normalization factor.
FULL = 0;
// Divide by the total number of output locations that do not take the
// ignore_label. If ignore_label is not set, this behaves like FULL.
VALID = 1;
// Divide by the batch size.
BATCH_SIZE = 2;
//
NONE = 3;
}
(1) 未设置normalization,但是设置了normalize:
normalize==1
: 归一化方式为VALID
normalize==0
: 归一化方式为BATCH_SIZE
(2)一旦设置normalization
,归一化方式则由normalization
决定,不再考虑normalize
。
对于softmax
的计算公式来说,对于比较小的输入数据来说是没有什么问题的,但是针对指数函数的特点,对于较大或者较小的数据进行softmax
计算会出现数据上溢与下溢的问题。计算机中浮点数的最大表示位数为2^64
,如果超过此数会产生上溢inf
,同样数据小于2^(-64)计算机在计算过程中会产生下溢-inf
。举个例子:
对任意a都成立,这意味着我们可以自由地调节指数函数的指数部分,一个典型的做法是取输入向量中的最大值:a=max{x1,x2…..xn}
这可以保证指数最大不会超过0,于是避免了上溢。即便剩余的部分下溢出了,加了a之后,也能得到一个合理的值。
并且softmax
不受输入的常数偏移影响,即softmax(x)=softmax(x+c)证明如下:
softmax函数计算时候为什么要减去一个最大值? caffe层解读系列-softmax_loss(http://blog.csdn.net/shuzfan/article/details/51460895)