Torchvision transforms become multi-image which.ToTensor()

username: YuvalA
cooked: <p>Hi,<br>
I am trying to work with some pictures of mine, loading with <code>ImageFolder</code> and making some transforms, when using <code>transforms.ToTensor()</code>, I receive multi-image picture.<br>
If I’m removing <code>ToTensor()</code>, it’s working as expected, however, need to be converted to Tensor.</p>
<p>What is the problem? (Pictures Attached)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/b/0b193a06c434cb43adf1a374baa1dbb480509581.png" data-download-href="https://discuss.pytorch.org/uploads/default/0b193a06c434cb43adf1a374baa1dbb480509581" title="1"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/b/0b193a06c434cb43adf1a374baa1dbb480509581_2_533x500.png" alt="1" data-base62-sha1="1AbiBpZBxSFKcTiksu1kM6oNZ1n" width="533" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/b/0b193a06c434cb43adf1a374baa1dbb480509581_2_533x500.png, https://discuss.pytorch.org/uploads/default/original/3X/0/b/0b193a06c434cb43adf1a374baa1dbb480509581.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/0/b/0b193a06c434cb43adf1a374baa1dbb480509581.png 2x" data-dominant-color="E3E3E4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">1</span><span class="informations">734×688 108 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/1/b18c1e9399ddeabb63c05ce14aa45790ff010e66.png" data-download-href="https://discuss.pytorch.org/uploads/default/b18c1e9399ddeabb63c05ce14aa45790ff010e66" title="2"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b18c1e9399ddeabb63c05ce14aa45790ff010e66_2_632x500.png" alt="2" data-base62-sha1="pkEIrjPc4py2qezlq4EHPB0W3Y2" width="632" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/1/b18c1e9399ddeabb63c05ce14aa45790ff010e66_2_632x500.png, https://discuss.pytorch.org/uploads/default/original/3X/b/1/b18c1e9399ddeabb63c05ce14aa45790ff010e66.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/1/b18c1e9399ddeabb63c05ce14aa45790ff010e66.png 2x" data-dominant-color="E1E4E7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">2</span><span class="informations">775×613 85.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: tom
cooked: <p>PyTorch uses CHW format (channels first), Matplotlib expects HWC, so you need to permute the image instead of using reshape. <code>.permute(1, 2, 0)</code> should do the trick.<br>
<code>reshape</code> 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 <a href="https://pytorch.org/deep-learning-with-pytorch" rel="noopener nofollow ugc">our book</a> if you’re interested.)</p>
<p>Best regards</p>
<p>Thomas</p>