MaxUnpool3d throws index error

I’m running the follwing code:

pool = torch.nn.MaxPool3d((4, 4, 4), return_indices=True)
unpool = torch.nn.MaxUnpool3d((4, 4, 4))
o, i = pool(x)      #x is tensor of size [1, 4, 256, 256]
y = unpool(o, indices=i, output_size=x.size())

But the unpool operation throws follwing error:
IndexError: tuple index out of range

I’m not sure what I’m doing wrong. I think I provided the indices and the output size correctly. Has anyone faced a similar problem? What can be the possible solution?

You are using 3d layers, while your input would work with 2d layers.
If you add another dimension, the code should work:

x = torch.randn(1, 4, 256, 256, 256)
pool = torch.nn.MaxPool3d((4, 4, 4), return_indices=True)
unpool = torch.nn.MaxUnpool3d((4, 4, 4))
o, i = pool(x)      
y = unpool(o, indices=i, output_size=x.size())

Thank you for your reply. However, I forgot to specify that given the input of size [1, 4, 256, 256], I wanted the output size of [1, 1, 64, 64],i.e., get the max-pooling along channels as well. But after seeing your approach, I added one more dimension at index zero and then it seems to work fine. I forgot about adding the batch dimension. Thank you for your help.