votes up 5

Got 3D input, but trilinear mode needs 5D input

Package:
torch
github stars 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":
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 5 votes down

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)

Jun 03, 2021 kellemnegasi answer
kellemnegasi 30.0k

Add a possible fix

Please authorize to post fix