Custom Dataloader with few patients

Hello everyone,

I will try to explain my problem.
I am using a triplet network with triplet loss, and to train my model i use patches extracted around many key-points detected from 3D scanners.
I have Few different patients (M), and few transformations per patients (N) with many keypoints per transformations (O keypoins). Then, i have approximately N*O patches per patients which i know exactly correspondences.
I make a dataloader where I generate an array containing X triplets possible. I use a dataloader to load data from this array which contain my triplets.

Here is my problem. I don’t know inter-patients correspondances and I can’t mixed patients inside a mini-batch. I want to make a dataloader who can take into account of this, same patient for the actual minibatch and with the same patient for the the mini-batch at each epoch.

Tell me if i’m not clear,
Thank you in advance !