I am preparing my data for a downstream CNN application in pytorch. I wish to use the transform methods = ToTensor() and Resize() both on the same dataset. I am not able to apply them together.
from torchvision.datasets import ImageFolder
from torchvision.transforms import ToTensor # In order to convert the datat to pytorch tensors
from torchvision.transforms import Resize
Able to apply them separately, but need to apply both these transforms on the same dataset. The image files are stored in "/content/sub_folder" directory.
dataset = ImageFolder("/content/sub_folder" , transform = Resize([224,224])) # ToTensor is method
dataset = ImageFolder("/content/sub_folder" , transform = ToTensor()) # ToTensor is method
How to apply both these transformation on all the images contained in my folder.
>Solution :
Hi you can use compose to use multiple transforms
from torchvision import transforms as T
from torchvision.datasets import ImageFolder
trans_comp = T.Compose([
T.Resize([224,224]),
T.ToTensor()
])
dataset = ImageFolder("/content/sub_folder", transform=trans_comp)