PyTorch DatasetLoader tensor should be a torch tensor. Got 
data_dir=&quot;D:\ML-ComputerVision\Datasets&quot;
train_transforms=transforms.Compose([transforms.RandomRotation(30),
                                     transforms.RandomResizedCrop(100),
                                     transforms.RandomHorizontalFlip(),
                                    transforms.Normalize([0.5,],[0.5,]),
                                    transforms.ToTensor()])

test_transforms=transforms.Compose([transforms.Normalize([0.5,],[0.5,]),
                                    transforms.ToTensor()])

train_data=datasets.ImageFolder(data_dir + &quot;/Train&quot;,transform=train_transforms)

test_data=datasets.ImageFolder(data_dir + &quot;/Test&quot;,transform=test_transforms)

trainloader=torch.utils.data.DataLoader(train_data,batch_size=32,shuffle=True)

testloader=torch.utils.data.DataLoader(test_data,batch_size=32,shuffle=False)

images, labels = next(iter(trainloader)) # &lt;-- Error line


I am getting  tensor should be a torch tensor. Got &lt;class 'PIL.Image.Image'&gt; error even though I have implemented transforms.ToTensor(). Any ideas how it can be fixed?

The way you chained your transforms, transforms.Normalizeis applied before transforms.ToTensor. But even though RandomRotation, RandomResizedCrop and RandomHorizontalFlip are image transforms that work on PIL images, transforms.Normalize only works on tensors (documentation here).
Simply putting ToTensor before Normalize should work.
