How to resize a PyTorch tensor?

Ger*_*_Ji 3 computer-vision pytorch tensor

Now I have a torch.Tensor of size (5, 1, 44, 44) in Pytorch.

  • 5 = batch size
  • 1 = channel
  • 44= image height
  • 44= image width

and I want to 'resize' it to shape (5, 1, 224, 224)

How can I do that? What functions should I use?

Sha*_*hai 5

It seems like you are looking for interpolate (a function in nn.functional):

import torch.nn.functional as nnf

x = torch.rand(5, 1, 44, 44)
out = nnf.interpolate(x, size=(224, 224), mode='bicubic', align_corners=False)
Run Code Online (Sandbox Code Playgroud)

  • 关于双三次插值的唯一警告是结果的范围可能比输入的范围更宽。如果这很重要,那么您可以使用双线性代替 (3认同)