def __getitem__(self,index):
sample= self.x_data[index], self.y_data[index]
if self.transform is not None:
sample=self.transform(sample)
return sample
def __len__(self):
return self.len
#######################################
class resize:
def call(self, sample):
inputs,targets = sample
inputs =transform.resize(inputs, (120, 120))
return inputs,targets
#######################################
train_set=swe_dataset(ts[0],tls[0],transform=resize())
#######################################
when I try to access the sample image by: im,_=next(iter(train_set)), I get the mentioned error. Could you help me to understand what is the problem in resizing? (because when I am not using transform everything works well)
I’m not sure, if you are passing the custom resize class as the transformation or torchvision.transforms.Resize.
However, transform.resize(inputs, (120, 120)) won’t work.
You could either create an instance of transforms.Resize or use the functional API:
It should work using your self.transform definition.
Could you post an executable code snippet to reproduce the error you are seeing so that we can have a look, please?
In your functional approach you are unpacking sample to inputs and target, thus passing a tensor to resize, while you are trying to apply self.transform on the tuple directly, which won’t work.
Unpack sample or pass self.x_data[index] directly to self.transform.