我一直在尝试在
Hoffer 和 Ailon, Deep Metric Learning Using Triplet Network , ICLR 2015中描述的 Caffe 中实现 softmax 版本的三元组损失。
我已经尝试过了,但我发现很难计算梯度,因为指数中的 L2 不是平方的。
有人可以在这里帮助我吗?
我一直在尝试在
Hoffer 和 Ailon, Deep Metric Learning Using Triplet Network , ICLR 2015中描述的 Caffe 中实现 softmax 版本的三元组损失。
我已经尝试过了,但我发现很难计算梯度,因为指数中的 L2 不是平方的。
有人可以在这里帮助我吗?
使用现有的 caffe 层实现 L2 规范可以为您省去所有的麻烦。
这是||x1-x2||_2
在 caffe 中计算“底部”x1
和的一种方法x2
(假设x1
和x2
是B
逐个C
斑点,计算维度差异B
的规范)C
layer {
name: "x1-x2"
type: "Eltwise"
bottom: "x1"
bottom: "x1"
top: "x1-x2"
eltwise_param {
operation: SUM
coeff: 1 coeff: -1
}
}
layer {
name: "sqr_norm"
type: "Reduction"
bottom: "x1-x2"
top: "sqr_norm"
reduction_param { operation: SUMSQ axis: 1 }
}
layer {
name: "sqrt"
type: "Power"
bottom: "sqr_norm"
top: "sqrt"
power_param { power: 0.5 }
}
对于论文中定义的三元组损失,您需要计算 L2 范数 forx-x+
和 for x-x-
,连接这两个 blob 并将 concat blob 馈送到一个"Softmax"
层。
不需要脏梯度计算。