使用半硬三联体时损失减少

时间:2017-09-07 07:01:09

标签: tensorflow neural-network conv-neural-network

Here是对三联学习的简短回顾。 我使用三个具有共享权重的卷积神经网络来生成面嵌入(否定),损失描述here

三胞胎损失:

anchor_output = ...  # shape [None, 128]
positive_output = ...  # shape [None, 128]
negative_output = ...  # shape [None, 128]

d_pos = tf.reduce_sum(tf.square(anchor_output - positive_output), 1)
d_neg = tf.reduce_sum(tf.square(anchor_output - negative_output), 1)

loss = tf.maximum(0., margin + d_pos - d_neg)
loss = tf.reduce_mean(loss)

当我只选择硬三元组(distance(anchor, positive) < distance(anchor, negative))时,损失非常小: 0.08 。 当我选择所有三胞胎时,损失会变得更大 0.17855 。这些只是10 000个三联体对的测试值,但我在实际组(600 000个三联体对)上得到了类似的结果。

为什么会这样?这是对的吗?

我使用SGD的动力,从学习率0.001 开始。

2 个答案:

答案 0 :(得分:3)

以下是三胞胎硬度术语的快速回顾:

  • easy triplets :丢失为0的三元组,因为d(a,p) + margin < d(a,n)
  • hard triplets :三元组,其中负数更靠近锚点而不是正数,即d(a,n) < d(a,p)
  • 半硬三胞胎:三元组,其中负数不比正数更接近锚点,但仍有正面损失:d(a, p) < d(a, n) < d(a, p) + margin

enter image description here

你在这里描述的内容:

  

当我只选择硬三联体(距离(锚,正)和<距离(锚,负))

实际上是选择半硬三胞胎和轻松三胞胎。你正在移除硬三胞胎,所以你的损失会更小。

答案 1 :(得分:1)

服用tf.sqrt(d_pos)和tf.sqrt(d_neg)后你得到了什么?