HingelossLayer
计算 one-of-many 分类任务的 hinge loss.
Hinge Loss 概念
定义为:
E(z)=max(0,1−z)
E
(
z
)
=
m
a
x
(
0
,
1
−
z
)
常用在SVM的最大化间隔分类中.
对于期望输出
t=+1,−1
t
=
+
1
,
−
1
和分类器分
y
y
, 预测值的 hinge loss 为:
l(y)=max(0,1−t∗y)
l
(
y
)
=
m
a
x
(
0
,
1
−
t
∗
y
)
这里,
y
y
应该是分类器决策函数的原是输出,而不是预测的最终类别结果.
例如,
线性SVMs,,其中
(w,b)
(
w
,
b
)
是超平面的参数,
x
x
为待分类的点.
当 和
y
y
符号相同(即预测到正确的类别)和
|y|>=1
|
y
|
>=
1
时, hinge loss:
l(y)=0
l
(
y
)
=
0
;
当
t
t
和 符号相反时,hinge loss
l(y)
l
(
y
)
则随着
y
y
的增加而线性增加(one-side error).
时,针对变量
y
y
,其hinge loss(蓝色线) vs. zero-one loss(青色,misclassification).
Note that the hinge loss penalizes predictions y < 1, corresponding to the notion of a margin in a support vector machine(SVM).
Caffe Layer 参数
- HingeLossLayer 参数:
- bottom - 输入 Blob 向量(长度为2)
- a. 大小的预测值
t
t
,其各值表示 类中的每一个类别的预测分数. 在SVM中,
t
t
是 D-维特征 和学习超平面参数
W∈RD×K
W
∈
R
D
×
K
作为输入,进行内积计算
XTW
X
T
W
得到的结果,故 HingeLossLayer 采用 InnerProductLayer(num_output=D)的预测值作为输入,不需要再学习参数即其它loss计算,即等价于线性SVM(一个全连接层加上一个Hingeloss相当于一个线性SVM).
- b. (N∗1∗1∗1) ( N ∗ 1 ∗ 1 ∗ 1 ) 大小的 labels t t ,其值为整数,,分别表示所对应的 K K 个类别中正确的类别标签.
- top - 输出 Blob 向量(长度为1)
- ,计算得到的 hinge loss:
E=1N∑Nn=1∑Kk=1[max(0,1−σ(ln=k)∗tnk)]p E = 1 N ∑ n = 1 N ∑ k = 1 K [ m a x ( 0 , 1 − σ ( l n = k ) ∗ t n k ) ] p
- Lp L p 范数, p=1 p = 1 , L1 范数; p=2 p = 2 , L2 范数,类似于 L2-SVM;
- if condition c o n d i t i o n , σ(condition)=1 σ ( c o n d i t i o n ) = 1 ;otherwise, σ(condition)=−1 σ ( c o n d i t i o n ) = − 1 .
Caffe prototxt定义
...... layer { name: "fc8voc" type: "InnerProduct" bottom: "fc7" top: "fc8voc" param { lr_mult: 10 decay_mult: 1 } param { lr_mult: 2 decay_mult: 0 } inner_product_param { num_output: 20 weight_filler { type: "gaussian" std: 0.01 } bias_filler { type: "constant" value: 0 } } } layer { name: "loss" type: "HingeLossMultiLabel" bottom: "fc8voc" bottom: "label" top: "loss" }
Reference
- ,计算得到的 hinge loss:
- a. 大小的预测值
t
t
,其各值表示 类中的每一个类别的预测分数. 在SVM中,
t
t
是 D-维特征 和学习超平面参数
W∈RD×K
W
∈
R
D
×
K
作为输入,进行内积计算
XTW
X
T
W
得到的结果,故 HingeLossLayer 采用 InnerProductLayer(num_output=D)的预测值作为输入,不需要再学习参数即其它loss计算,即等价于线性SVM(一个全连接层加上一个Hingeloss相当于一个线性SVM).