Take a look at this example:
pool = nn.MaxPool2d(2, return_indices=True)
x = torch.arange(2*16).view(2, 1, 4, 4).float()
print(x)
# tensor([[[[ 0., 1., 2., 3.],
# [ 4., 5., 6., 7.],
# [ 8., 9., 10., 11.],
# [12., 13., 14., 15.]]],
# [[[16., 17., 18., 19.],
# [20., 21., 22., 23.],
# [24., 25., 26., 27.],
# [28., 29., 30., 31.]]]])
out, idx = pool(x)
print(out)
# tensor([[[[ 5., 7.],
# [13., 15.]]],
# [[[21., 23.],
# [29., 31.]]]])
print(idx)
# tensor([[[[ 5, 7],
# [13, 15]]],
# [[[ 5, 7],
# [13, 15]]]])
unpool = nn.MaxUnpool2d(2)
y = unpool(out, idx)
print(y)
# tensor([[[[ 0., 0., 0., 0.],
# [ 0., 5., 0., 7.],
# [ 0., 0., 0., 0.],
# [ 0., 13., 0., 15.]]],
# [[[ 0., 0., 0., 0.],
# [ 0., 21., 0., 23.],
# [ 0., 0., 0., 0.],
# [ 0., 29., 0., 31.]]]])
to understand what the returned indices from an nn.MaxPool2d
layer represent and how you could create “artificial indices”.
I also don’t fully understand what your use case would be if you want to randomly create these indices.