TypeError: 'Compose' object is not iterable

I am trying to create a custom class for my dataset. Can anyone figure out what is wrong in the code given below?

class Map_dataset(Dataset):
    def __init__(self,root_dir,transforms=None):
        self.transforms=transforms
        self.root_dir=root_dir
        self.list_dir=os.listdir(self.root_dir)
    def __getitem__(self,idx):
        img_path=os.path.join(self.root_dir,self.list_dir[idx])
        whole_image=np.array(Image.open(img_path))
        input_image=torch.tensor(whole_image[:,:600,:])
        target_image=torch.tensor(whole_image[:,600:,:])
        if (self.transforms):
            for t in self.transforms:
                input_image=t(input_image)
                target_iage=t(target_image)
        return input_image,target_image
    def __len__(self):
        return len(self.list_dir)

img_size=256
batch_size=16
composed=torchvision.transforms.Compose([torchvision.transforms.Resize((img_size,img_size))])
data=Map_dataset("../input/pix2pix-maps/train",composed)
data_loader=DataLoader(data,batch_size,shuffle=True)
input_images,target_images=iter(data_loader).next()
print(input_images.shape,target_images.shape)

Based on the error message, the issue is in trying to iterate transforms.Compose, which is not working:

for t in self.transforms:
    input_image=t(input_image)
    target_iage=t(target_image)

transforms.Compose will apply the transformation in the specified order, so you can use it directly:

input_image = self.transforms(input_image)

How can I make sure to apply the same transforms to the input_image and the target_image? For example if I have RandomFlip or something other “random” transformation.