在caffe中,默认的以loss结尾的layer可以作为loss层,但是中间的层同样可以作为loss层.原因是这样的:
有一个和这个相关的参数:loss_weight,它决定了你的每个loss层占最好的loss的大小.
在以loss结尾的layer里面, loss_wight的大小为1. 在不是以loss结尾的layer里面,它的loss_weight为0.
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "pred"
bottom: "label"
top: "loss"
loss_weight: 1 #这个是默认的,可以不写的.
}
如果我们想在一个net里,包含多个loss层的话,我们就可以设置他们对应的loss_weight在大小,这就相当于一个权值.(如一个网络中,我们即用softmaxWithloss用来分类,也用EuclideanLoss用来计算重构输入的loss).
最后在计算总的loss的时候,它的输出可以用下面的伪代码表示:
loss := 0
for layer in layers:
for top, loss_weight in layer.tops, layer.loss_weights:
loss += loss_weight * sum(top)
softmax: 类型为:SoftmaxWithLoss
它的类型为:SoftmaxWithLoss.它其实就是一个 softmax层,然后跟了个multinomial logistic loss层. 它比单独用softmax层可以使梯度值更稳定.
sum-of-squares/也叫euclidean:
就是平时我们说的平方差代价函数.
hinge Loss: 类型:HingeLoss
最常用在 SVM 中的最大化间隔分类中等. hinge loss常分为1vs all hinge和squared hinge loss,即 L1 与L2hange.
# L1 Norm
layer {
name: "loss"
type: "HingeLoss"
bottom: "pred"
bottom: "label"
}
# L2 Norm
layer {
name: "loss"
type: "HingeLoss"
bottom: "pred"
bottom: "label"
top: "loss"
hinge_loss_param {
norm: L2
}
}
sigmoid cross-entropy loss:
就是平常所见的交叉熵损失函数. 类型:SigmoidCrossEntropyLoss
infogain loss:信息增益损失函数: ,类型:InfogainLoss