Search code examples
pytorch

Pytorch tensor to change dimension


I have a RGB image tensor as (3,H,W), but the plt.imshow() can not show RGB image with this shape. I want to change the tensor to (H,W,3). How can I do that, is pytorch function .view() can do that?


Solution

  • Find the method. use pytorch permute() method, see details: https://www.geeksforgeeks.org/python-pytorch-permute-method/

    code:

    image.permute(1, 2, 0)