wanji / caffe-sl

caffe for Similarity Learning
Other
83 stars 53 forks source link

loss function for pairwise ranking loss layer #1

Closed muneebshahid closed 8 years ago

muneebshahid commented 8 years ago

Hello @wanji , i have been looking at your code and trying to understand it. First off thanks a lot for sharing it.

Currently I cant wrap my head around the line 42 in pair_wise_ranking_layer.cppif (pos_diff[i] && pos_sim[i] > neg_sim[i]) Why do you need the part && pos_sim[i] > neg_sim[i]). i.e margin = .5 pos_sim=.6 neg_sim=.8, then despite having loss the if condition will fail resulting in zero gradient. What am I missing?

Apologies if it is a stupid question, I am still new to caffe. Also I noticed the gpu counter part for pairwise ranking is missing, is there any specific reason why? should I implement it myself?

Thanks in advance. Muneeb

wanji commented 8 years ago

@muneebshahid Thanks for your interests! The restriction pos_sim[i] > neg_sim[i] is to filter out the triplets that are too hard. You can refer this paper for more details (Section 3.2. Triplet Selection):

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

I will add an option to control this, so that we can turn on/off this feature.

As the computation in the PairwiseRankingLossLayer is very simple, the GPU counter part may seem unnecessary.

wanji commented 8 years ago

@muneebshahid

An option sample has been added to the TripletLossParameter. It is set to false by default, which means no filtering.

muneebshahid commented 8 years ago

@wanji Thanks a lot for the update. I will have a look at the paper as well. thanks again.

muneebshahid commented 8 years ago

Closing the issue.