I am trying to work with some pictures of mine, loading with
ImageFolder and making some transforms, when using
transforms.ToTensor(), I receive multi-image picture.
If I’m removing
ToTensor(), it’s working as expected, however, need to be converted to Tensor.
What is the problem? (Pictures Attached)
PyTorch uses CHW format (channels first), Matplotlib expects HWC, so you need to permute the image instead of using reshape.
.permute(1, 2, 0) should do the trick.
reshape does not rearrange your data in memory, it just changes where PyTorch thinks after how many items in memory it should start the next line. (We discuss memory layout of tensors in some detail in Chapter 3 of our book if you’re interested.)