Invalid max index when MaxUnpool1d

I am trying to build an auto-encoder but I keep stumbling upon an indexing issue when trying to unpool.

This is my code so far for the encoding:

from torch.autograd import Variable

test_in = Variable(torch.rand(1, 73, 480))

layer1 = nn.Conv1d(73, 256, kernel_size=3, stride=1, padding=2, bias=True)
layer2 = nn.ReLU()
layer3 = nn.AdaptiveMaxPool1d(240, return_indices=True)
drop_out = nn.Dropout(0.25)

out = drop_out(test_in)
out = layer1(out)
out = layer2(out)
out, indices = layer3(out)

This is the code for my decoding:

layer1_d = nn.Conv1d(256, 73, kernel_size=2, stride=1, padding=2, bias=True)
drop_out_d = nn.Dropout(0.25)
unpool_d = nn.MaxUnpool1d(3,1)
out_d = unpool_d(out, indices, output_size= (1, 256, 480))
out_d = drop_out_d(out_d)
out_d = layer1_d(out_d)

But I get this error on the unpool step

RuntimeError: Found an invalid max index: 480 (output volumes are of size 480x1

The resulting output ( out ) and indices from the encoding step have the following shape, respectively torch.Size([1, 256, 240]) and torch.Size([1, 256, 240]) .


This might be a small bug in the AdaptiveMaxPool module.
Could you give a small code sample we can run to reproduce the issue please?