One possible approach would be to use ImageFolder internally in a custom Dataset and replace the root folder in the current path:

class MyDataset(Dataset):
    def __init__(self, train1, transform=None):
        self.dataset1 = datasets.ImageFolder(root=train1)
        self.transform = transform

    def __getitem__(self, index):
        # Get samples from train1
        x1, y = self.dataset1[index]
        # Get corresponding sample from train2
        path = self.dataset1.samples[index][0]
        path = path.replace('train1', 'train2')
        print('Loading ', path)
        x2 = self.dataset1.loader(path)
        
        if self.transform:
            x1 = self.transform(x1)
            x2 = self.transform(x2)
            
        return x1, x2, y
        
    def __len__(self):
        return len(self.dataset1)


dataset = MyDataset(train1='./data/train1')