Hi there, i’m create siamese networks for face comparison, folder image have structure:

face_db


id1:




img11.jpg




img12.jpg




…




id2:




img21.jpg




img22.jpg




…



So, how to create dataset contain pair image? There is code i search but I found it missing, because, if i have n image then i have n*(n-1)/2 item, but this have n item? Can i help me please?
class SiameseNetworkDataset(Dataset):
    
    def __init__(self, imageFolderDataset):
        self.imageFolderDataset = imageFolderDataset    
        
    def __getitem__(self, index):
        img0_tuple = random.choice(self.imageFolderDataset.imgs)
        
        should_get_same_class = random.randint(0,1)
        
        if should_get_same_class:
            while True:
                img1_tuple = random.choice(self.imageFolderDataset.imgs) 
                if img0_tuple[1]==img1_tuple[1]:
                    break
        else:
            while True:
                img1_tuple = random.choice(self.imageFolderDataset.imgs) 
                if img0_tuple[1] !=img1_tuple[1]:
                    break

        img0 = embedding_img(img0_tuple[0])
        img1 = embedding_img(img1_tuple[0])
        
        return img0, img1, torch.from_numpy(np.array([int(img1_tuple[1]!=img0_tuple[1])],dtype=np.float32))
    
    def __len__(self):
        return len(self.imageFolderDataset.imgs)