How i realise this?

In practice, we define a subset S of all template images for each training iteration. Before training begins, we sequentially examine each label in the training batch and remove the duplicated labels,then accumulate unique label from a shuffled label set until the number of unique label reaches the predefined batch size N. This sampling and accumulating strategy ensures that the template images corresponding to the training samples are totally covered in the subset S.
.