2

我一直在尝试在
Hoffer 和 Ailon, Deep Metric Learning Using Triplet Network , ICLR 2015中描述的 Caffe 中实现 softmax 版本的三元组损失。

我已经尝试过了,但我发现很难计算梯度,因为指数中的 L2 不是平方的。

有人可以在这里帮助我吗?

4

2 回答 2

3

使用现有的 caffe 层实现 L2 规范可以为您省去所有的麻烦。

这是||x1-x2||_2在 caffe 中计算“底部”x1和的一种方法x2(假设x1x2B逐个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"层。
不需要脏梯度计算。

于 2016-03-29T12:08:44.830 回答
2

这是一个数学问题,但它就在这里。第一个方程是你习惯的,第二个是你在它没有平方时所做的。

范数的推导

于 2016-03-29T10:38:56.567 回答