Triplet sampling

Could anyone recommend a good way to sample triplets from datasets, where a triplet is defined as examples (x1, x2, x3) where x1, x2 are from the same class and x3 is from a different class?

1 Like

You can construct all possible triplets and them sample randomly in this list

That seems like it might take up an excessive amount of memory. Is there a way to use a custom DataLoader?

This two projects might help.

This repo also looks fantastic, it looks like the author has even written up several of the popular triplet selection strategies into pytorch dataloaders