I have problems applying transforms

Hi, I am a beginner in pytorch and I have some problems applying transforms on my dataset, can I get some suggestions ? :confused:

train_transforms = transforms.Compose([
transforms.Resize(input_size),
transforms.RandomResizedCrop(input_size),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])

train_dataset = torch.utils.data.TensorDataset(torch.from_numpy(X_train), torch.from_numpy(y_train))

train_dataset = torch.utils.data.Subset(train_dataset, indices = np.arange(train_dataset.tensors[0].shape[0]))

train_dataset.dataset.transform = train_transforms

‘’‘here I have another similar val_load but I omit it to simplify the reading’’’
train_load = torch.utils.data.DataLoader(train_dataset.dataset, batch_size = batch_size, shuffle = True)
dataloaders = {‘train’: train_load, ‘val’:val_load}

What you should know is that I am using tensordataset because I don’t have images, and I am using subset so I can apply the transforms. Any ideas ?

Some transformations would already work on tensors in the latest torchvision release.
However, you could use transforms.ToPILImage() to transform the input tensors to Images first, apply the transformations, and transform them back to tensors.
I’m not sure, if this is the issue or where you are stuck exactly.

PS: you can add code snippets by wrapping them into three backticks ```, which makes debugging easier :wink:

Thank you for the answer and for the trick too :grinning: