Applying ToTensor() rotates the image CW 90degrees

import torch
from PIL import Image
from torchvision import transforms

img = Image.open(filename)
print(img.size)
content_transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Lambda(lambda x: x.mul(255))
    ])

content_image = content_transform(content_image)
print(content_image.shape)

When i load an image using PIL and appply ToTensor() transform on it, the tensor rotates 90degrees Clockwise

img.size: (2592,1944)
content_image.shape: torch.Size([3,1994,2592])

Any idea why is this happening or how can i fix this?
Thanks in advance :slight_smile:

PIL returns the size as [width, height] without the number of channels.
ToTensor() permutes the image array to [channels, height, width], which is the expected input shape for image tensors for 2-dimensional modules, so your shape looks alright. :wink: