Hello, I want to set the transform attribute of a Dataset object once I have already instantiated the object - I try to do that using the setattr method of python, but it does not work - below is a minimum working example.
import torch
import numpy as np
from torch.utils.data import Dataset
import torchvision.transforms as transforms
from torch.utils.data import TensorDataset
trans = transforms.Compose([transforms.Resize(size=224), transforms.CenterCrop(size=(224, 224)), transforms.ToTensor(), transforms.Normalize(mean=(0.48145466, 0.4578275, 0.40821073), std=(0.26862954, 0.26130258, 0.27577711))])
images = torch.randn(50000, 3, 32, 32)
labels = torch.randint(9, (50000,1))
dset = TensorDataset(images, labels)
setattr(dset, 'transform', trans)
for idx, (x, y) in enumerate(dset):
print(x.shape)
break
The output of this snippet gives me -
torch.Size([3, 32, 32])
but rather, we should be getting
torch.Size([3, 224, 224])
why is setting attribute externally not working?
Please let me know if I am missing anything and thanks for your time!