I want to apply one common transformation to image, followed by three different independent transformation

as per shown here

transform = T.Compose([
T.RandomApply(torch.nn.ModuleList([T.ColorJitter()]), p=0.25)

transform1 = T.Compose([

transform2 = T.Compose([
T.Resize((384, 384)),

transform3 = T.Compose([
T.Resize((512, 512)),

My code in dataloader

               img1 = self.img_transform(img1) 
   if self.img_transform1 is not None:
       img1 = self.img_transform1(img1)
       img2 = self.img_transform2(img1)
       img3 = self.img_transform3(img1) 

however I am gettng error
TypeError: pic should be PIL Image or ndarray. Got <class ‘torch.Tensor’>

I know the other transformation want input as PIL image, thats why it showing error. How to tackle this situation. transform is common transformation I want to apply.

1 Like

What happens if you remove the “ToTensor()” conversion ?

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class ‘PIL.Image.Image’>

It will give this error. Also, i do want to apply the normalise the values in 0 and 1

are you using read_image to load the image?
Now paying more attention it seems you use PIL, but no info included in the post about it.

Can you include a more complete code ?

I am using
def default_loader(path):
return Image.open(path).convert(‘RGB’)

I could take a look if the full relevant code snippet is included, so I can reproduce it locally, not by pieces like this