Skip to content

Commit 0a04aaa

Browse files
committed
fixing ToTensor bugs
1 parent 386a91b commit 0a04aaa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

torchvision/transforms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def __call__(self, pic):
3333
else:
3434
# handle PIL Image
3535
img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes()))
36-
img = img.view(pic.size[0], pic.size[1], 3)
37-
# put it from WHC to CHW format
36+
img = img.view(pic.size[1], pic.size[0], 3)
37+
# put it from HWC to CHW format
3838
# yikes, this transpose takes 80% of the loading time/CPU
39-
img = img.transpose(0, 2).contiguous()
39+
img = img.transpose(0, 1).transpose(0, 2).contiguous()
4040
return img.float().div(255)
4141

4242
class ToPILImage(object):

0 commit comments

Comments
 (0)