<p>In practice, if your dataset is large, it is infeasible to sample hard triplet from the whole dataset. In fact, you can choose hard triplet for only a small proportion of your training dataset, which will be much more time-saving. After training the network using the hard triplet generated for K iterations. You feed the network with the next batch of images from the dataset and generate the new hard triplet.</p>

<p>In this way, the computation cost is acceptable and network is gradually improving as the training process goes.</p>

<p>see the <a href="https://arxiv.org/pdf/1604.01325.pdf" rel="nofollow noreferrer">article here</a> for more reference.(section 5.1)</p>
Efficient hard data sampling for triplet loss
<p>I am trying to implement a deep network for triplet loss in Caffe.
When I select three samples for anchor, positive, negative images randomly, it almost produces zero losses. So I tried the following strategy:</p>

<pre><code>If I have 15,000 training images,
1. extract features of 15,000 images with the current weights.
2. calculate the triplet losses with all possible triplet combinations.
3. use the hard samples with n largest losses, and update the network n times.
4. iterate the above steps every k iterations to get new hard samples.
</code></pre>

<p>The step 1 is fast, but I think step 2 is very time-consuming and is really inefficient. So, I wonder whether there are other efficient strategies for hard data sampling.</p>

<p>Thanks.</p>