Hi everyone,
I’m implementing a Siamese network. Herefor I always need two images, which should be randomly sampled with p=0.5 as both from the same class and from different classes.
My idea is
class SiameseDataset(MyOwnDataset):
    # Source: https://github.com/harveyslash/Facial-Similarity-with-Siamese-Networks-in-Pytorch/blob/master/Siamese
    # -networks-medium.ipynb

    def __init__(self, args, file, augumentation=None):
        super().__init__(args, file, augumentation)

    def __getitem__(self, index):
        # We need approx 50 % of  images of the same class
        same_class = random.randint(0, 1)
        img_0 = self.data[index]
        label_0 = self.labels[index]
        if same_class:
            while True:
                # keep looping till the same class image is found
                index_1 = random.randint(0, self.__len__())
                label_1 = self.labels[index_1]

                if label_0 == label_1:
                    img_1 = self.data[index_1]
                    break
        else:
            while True:
                index_1 = random.randint(0, self.__len__())
                label_1 = self.labels[index_1]
                if label_0 != label_1:
                    img_1 = self.data[index_1]
                    break

        return (img_0, label_0), (img_1, label_1)


I face now the issue that MyOwnDataset is a ConcatDataset out of 6 Datasets belonging all to different classes. So when I need a sample from a different dataset, this does not work as self.data[index] belongs to samples only from the same class.
Do you have an idea how I could solve this?
Thanks and beste regards
Jonas