wanji / caffe-sl

caffe for Similarity Learning
Other
83 stars 53 forks source link

Clarification on the loss that is minimized in BatchTripletLossLayer #2

Open iacopomasi opened 8 years ago

iacopomasi commented 8 years ago

Hi @wanji , could you please clarify the loss that is minimized in BatchTripletLossLayer layer and point to a paper that is explaining it?

In particular what is the mu parameter in

layer { name: "loss" type: "BatchTripletLoss" bottom: "ip2norm" bottom: "label" top: "loss" top: "accuracy" top: "debug" triplet_loss_param { margin: 0.5 mu: 0.5 } }

It looks like from the code that implements Scheme II in the paper you mentioned.

From the code seems that you re-implemented this this but I am not sure. I cannot find your parameters in that paper.

Thank you.

wanji commented 8 years ago

Hi @iacopomasi ,

Actually the BatchTripletLossLayer is an re-implementation of the FaceNet paper from Google:

FaceNet: A Unified Embedding for Face Recognition and Clustering
Florian Schroff, Dmitry Kalenichenko, James Philbin

The major differences between the MM paper and FaceNet is that the MM paper uses pre-generated triplets while FaceNet generating triplets from an batch at training time. In addition, FaceNet remove the triplets that are too hard for training, i.e. in which the distance between positive pair is larger than that between negative pair.

iacopomasi commented 7 years ago

Hi @wanji, thanks for the clarification but it still not clear to me. Reading the post after a few months 😄 and looking into your code, it seems that here you have a trade-off between 2 losses:

rank_loss * mu_ + pair_loss * one_minus_mu;

The trade-off is governed by mu parameter:

  1. rank_loss seems the same as you said similar to the FaceNet paper (loss over all triplets) but the other pair_loss is unclear. Is pair_loss the average distance of same-class pairs?
  2. Finally, is the smp_rank_loss loss used somehow or just shown for debug? This seems the same as rank_loss but computed on selected triplet, more closely to FaceNet paper

Thanks.