Got 3D input, but trilinear mode needs 5D input
Package:
torch
50580

Exception Class:
NotImplementedError
Raise code
if input.dim() == 4 and mode == "bicubic":
assert align_corners is not None
return torch._C._nn.upsample_bicubic2d(input, output_size, align_corners, scale_factors)
if input.dim() == 3 and mode == "bilinear":
raise NotImplementedError("Got 3D input, but bilinear mode needs 4D input")
if input.dim() == 3 and mode == "trilinear":
raise NotImplementedError("Got 3D input, but trilinear mode needs 5D input")
if input.dim() == 4 and mode == "linear":
raise NotImplementedError("Got 4D input, but linear mode needs 3D input")
if input.dim() == 4 and mode == "trilinear":
raise NotImplementedError("Got 4D input, but trilinear mode needs 5D input")
if input.dim() == 5 and mode == "linear":
raise NotImplementedError("Got 5D input, but linear mode needs 3D input")
if input.dim() == 5 and mode == "bilinear":
Links to the raise (1)
https://github.com/pytorch/pytorch/blob/e56d3b023818f54553f2dc5d30b6b7aaf6b6a325/torch/nn/functional.py#L3701Ways to fix
When the torch.nn.Upsample initialized in 'trilinear' mode a 5D input is expected.
Step to reproduce the error:
import torch
input_3x3 = torch.zeros(3, 3).view(1,3, 3) #Here a 3D tensor is provided
m = torch.nn.Upsample(scale_factor=2, mode='trilinear')
m(input_3x3)
Fixed version of the code
The tensor should be reshaped to a 5D.
from torch import nn
# here the input is reshaped to 5D tensor. this fixes the error
input_5x5 = torch.zeros(3, 3).view(1,1, 1, 3, 3)
m = nn.Upsample(scale_factor=2, mode='trilinear')
m(input_5x5)
Add a possible fix
Please authorize to post fix