Resizing images in with DataLoader

I am going through the ant bees transfer learning tutorial, and I am trying to get a deep understanding of preparing data in Pytorch. I removed all of the transformations except ToTensor, but it seems
you need to make sure images need to be resized?

So I am trying this:

train_data = ImageFolder(root = os.path.join(root_dir, ‘train’), transform=transforms.Compose([Resize(256),ToTensor()]))
train_loader = iter(dataloader)
x,y = next(train_loader)

However I am still getting a runtime Error:

`Sizes of tensors must match except in dimension 0. Got 371 and 375 in dimension 2 at ..\aten    \src\TH/generic/THTensor.cpp:711`

Preformatted textIs there another transformation I need to add?

PS: Is there no preview button on these boards? I am trying out different formating options but I can’t seem to find a way to preview the options. Thank you. .

1 Like

If size is a sequence like (h, w), output size will be matched to this.

If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size)

I think this is the problem. Instead of Resize(256) try, Resize(256,256). This will alter the aspect ratio. But, first check and let us know the outcome.

Yes that seems to be case. Thank you so much.