luhaofang / tripletloss

tripletloss in caffe
MIT License
322 stars 152 forks source link

Negative mining in TripletSelectLayer #57

Open PramuPerera opened 6 years ago

PramuPerera commented 6 years ago

Hello,

When selecting the negative triplet, right now, you are picking the sample furthest away from the anchor.

for i in range(self.triplet): negative_feature = bottom[0].data[i+self.triplet2] a_n = archor_feature - negative_feature an = np.dot(a_n,a_n) ans[i+self.triplet2] = an ans = sorted(ans.items(), key = lambda d: d[1], reverse = True)

top_negative.append(bottom[0].data[ans[i][0]])

If we are mining the hardest negative sample, shouldn,'t we consider the closest negative sample to the anchor? Correct me if I'm wrong. Thanks!

luhaofang commented 6 years ago

Hi, you are not wrong, the select method is used to smooth the gradient, much depends on your dataset.