Apply same transformation to CycleGAN for same patches

How can I apply the same transformation to both images in the cycleGAN implementation of Zhu et al. ?

I want to go over the same patches over images instead of random ones but still use an aligned dataset.

This is the snippet where I have to change the A,B self.transform(img) part but nothing works so far:

   def __getitem__(self, index):
        A_path = self.A_paths[index % self.A_size]
        if self.opt.serial_batches:
            index_B = index % self.B_size
            index_B = random.randint(0, self.B_size - 1)
        B_path = self.B_paths[index_B]
        A_img ='RGB')
        B_img ='RGB')

        A = self.transform(A_img)
        B = self.transform(B_img)```

I guess I have to change A and B in order to undergo the same transformation. Is that right?

I’m not sure to understand the use case correctly.
Are you trying to get the same patch or to apply identical transformations for both patches?
In the latter case, you could use the functional API of torchvision.transforms.
Have a look at this post for an example.