Resizing 4D to 4D, but only on one dimension

Hi,
I have a Tensor of A[80,512,7,7], and I want to resize it to a Tensor of B[80,2048,7,7].
How can I get the best interpolation?

I wanted to simply use interpolate asinterpolate(A,size=B.shape), but I get an error of:
Expected a list of 2 units but got 4 for argument #2, output size.
I tried interpolate(A,size=B.shape, scale_factor=None, mode='bilinear') , but I get the same error.

@yegane
I think you set value for argument size by mistake. Currently interpolate function supports temporal, spatial and volumetric sampling, i.e. expected inputs are 3-D, 4-D or 5-D in shape. The input dimensions are interpreted in the form: mini-batch x channels x [optional depth] x [optional height] x width.
For your case, if you want to resize on 4D input, then interpolate does spatial sampling and interpolates for the last 2 dimension(height * width), so the list length of argument size must be less than 2. Can you let me know why would you like to interpolate in the second dimension(channels)? Otherwise, reshape your input first and interpolate later.
For example:

>>> input = torch.randn(1, 1, 2, 2)
>>> input
tensor([[[[-0.7523, -1.5534],
          [-0.2479,  0.6668]]]])
>>> F.interpolate(input, 4, mode='bilinear')
tensor([[[[-0.7523, -0.9526, -1.3531, -1.5534],
          [-0.6262, -0.7192, -0.9053, -0.9983],
          [-0.3740, -0.2525, -0.0097,  0.1118],
          [-0.2479, -0.0192,  0.4382,  0.6668]]]])
>>> F.interpolate(input, [4, 2], mode='bilinear')
tensor([[[[-0.7523, -1.5534],
          [-0.6262, -0.9983],
          [-0.3740,  0.1118],
          [-0.2479,  0.6668]]]])
2 Likes