ImageFolder rotates images by 90 degrees to the left

Hi all,

I found out that when loading images with the ImageFolder dataset, the images are rotated by 90 degrees to the left.

The following code opens a single images from the specified folder, permutes the axis such that the format is H x W x C and then displays the image.

data = torchvision.datasets.ImageFolder('images', torchvision.transforms.Compose([torchvision.transforms.ToTensor()]))
data_loader = torch.utils.data.DataLoader(data, batch_size=1, shuffle=True, num_workers=2)

x, _ = next(iter(data_loader))
x = x.permute(0, 3, 2, 1)

x = x[0].numpy()
im = Image.fromarray(np.uint8(x * 255))
im.show()

The image is rotated by 90 degrees to the left. I am wondering why this is the case. Is this on purpose? Or did I use ‘permute’ incorrectly?

Cheers!

Image tensors are usually loaded as [batch_size, c, h, w].
Could you try to permute them as .permute(0, 2, 3, 1) to get [batch_size, h, w, c] and check your code again?

1 Like