回答

14

我假設你定義損失層

layer { 
    name: "tripletLoss" 
    type: "TripletLoss" 
    bottom: "anchor" 
    bottom: "positive" 
    bottom: "negative" 
    ... 
} 

現在你需要計算梯度w.r.t每個「底」 S的。
enter image description here

梯度WRT 「錨」 輸入(fa):
enter image description here

梯度WRT 「正」 輸入(fp):

損失由下式給出
enter image description here

「負」輸入的梯度(fn):
![enter image description here


原來的計算(我離開這裏了感情上的原因......)

enter image description here

請參閱comment修正的最後一項。

+4

最後一個,「負面」的梯度,不應該是2(fa - fn )? –

+0

@MickeyShine是的,你是對的。 – Shai

+0

@MickeyShine你應該看看['EucleadianLossLayer']的實現(https://github.com/BVLC/caffe/blob/master/src/caffe/layers/euclidean_loss_layer.cpp),看看這些計算是如何實現的在caffe。 – Shai