Custom Dataset for Siamese CNN

Hi all,
I’m building a particular kind of dataset for a Siamese neural network.
I was inspired by this topic: Dataloader for a Siamese Model with ConcatDataset, but my implementation is slightly different since I need to take the 2 images, passed to the net, from 2 different folders and I need that the first and the second one images are always taken from the respective dataset.
So I tried the implementation linked but it doesn’t fit my problem because the Concat function don’t respect the constraint discussed.
Thus, my question is: is there a way to tell the Concat function to respect these constraint?

P.s. The 2 dataset/folders are of different size so I think that the one with less images must recycle some of its images to be combined with others of the second bigger dataset

Anyone got some tips for this task?

Since your use case seems to be a bit more complicated I would recommend to implement a custom Dataset as explained in this tutorial.
This would allow you to implement the loading logic (and correspondence of the image folders) manually.