Conflict error message: Only 3D, 4D and 5D input Tensors supported (got 3D) for the modes: nearest | linear | bilinear | bicubic | trilinear (got bicubic)

pytorch version ‘1.1.0’

Here is simple code that make error

import torch
import torch.nn.functional as F

img = torch.rand(1,128,128)
img2 = F.interpolate(img, scale_factor=(1,0.5,0.5), mode="bicubic")

and error

Traceback (most recent call last):
  File "/home/tt/project/crowd_counting_framework/bug/interpolate_bug.py", line 8, in <module>
    img2 = F.interpolate(img, scale_factor=(1,0.5,0.5), mode="bicubic")
  File "/home/tt/anaconda3/envs/pytorch_gpu/lib/python3.7/site-packages/torch/nn/functional.py", line 2577, in interpolate
    " (got {})".format(input.dim(), mode))
NotImplementedError: Input Error: Only 3D, 4D and 5D input Tensors supported (got 3D) for the modes: nearest | linear | bilinear | bicubic | trilinear (got bicubic)

The error is conflict by it self.
It said “Only 3D, 4D and 5D input Tensors supported”, but confirm got 3D.
also, " nearest | linear | bilinear | bicubic | trilinear" => but got bicubic

It should OK.

To rescale a 2D 1-channel image the input should be 4D: batch x chan x height x width
The error message indeed is a bit unclear.

See the interpolate() in the docs:

"Currently temporal, spatial and volumetric sampling are supported, 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.

The modes available for resizing are: nearest, linear (3D-only), bilinear, bicubic (4D-only), trilinear (5D-only), area"

The following should work:

img = torch.rand(1,1,128,128)
img2 = F.interpolate(img, scale_factor=(0.5,0.5), mode="bicubic")
2 Likes