No, that was my mistake, remove ToPILImage from transfroms list and it will be ok.



 Nikronic:

trans = transforms.Compose([transforms.ToPILImage(),  # remove this
                            transforms.RandomHorizontalFlip(0.5),
                            ...
                            ...
                            transforms.ToTensor(),
                            transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])



The explanation would be that ImageFolder converts to PIL by itself and ToPIL was converting a PIL image to PIL which is wrong as `ToPIL only needs tensor.