F.interpolate 's misleading error messages and documentation

Hello,

I think I found some inconsistency between documentation, behavior and error messages while using F.interpolate.

Regarding mode=linear documentation says that input should be a 3D tensor. That’s why we see expected error when passing the 4D tensor.

Code

x = torch.rand(1,2,100,100)
F.interpolate(x, size=(64,64), mode="linear")

Error:

NotImplementedError: Got 4D input, but linear mode needs 3D input

But at the same time when we pass 3D tensor to this very function error states that it’s 1D.

Code

x = torch.rand(1,100,100)
F.interpolate(x, size=(64,64), mode="linear")

Error

ValueError: size shape must match input shape. Input is 1D, size is 2

Why is this way? What do I miss?

mode='linear' is for data with only one spatial dimension. Image data has 2 spatial dim.
for image like data, you should use mode='bilinear'.
The following code will work for 1d data. 100 is #numchannel for 1d input.

x = torch.rand(1,100,100)
F.interpolate(x, size=(64), mode="linear")

or for 2d,

x = torch.rand(1,1,100,100)
F.interpolate(x, size=(64,64), mode="bilinear")

Yes, thank you it’s a good explanation. Documentation says

“size”` — output spatial size

so it’s needed to understand what is “spatial” dimensions of the input tensor.