Resizing the torch tensor

I have a torch tensor of size torch.Size([1, 128, 56, 128])

1 is channel, 128 is the width, and height. 56 is the number of images.

How can I resize it to torch.Size([1, 56, 128, 128]) ?

thankyou

You need to permute or transpose the tensor:

import torch
a = torch.randn(1, 128, 56, 128)
print(a.permute(0, 2, 1, 3).shape)
print(a.transpose(2, 1).shape)
torch.Size([1, 56, 128, 128])
torch.Size([1, 56, 128, 128])
1 Like

thankyou, it worked! :slight_smile: