Hey,
So I was wondering about the padding function of nn.functional:
I am working with 3d images which, outside of the net need padding for some processing.
pad() works fine when just leaving the mode at its default. But trying to use mode=‘reflect’ or mode=‘replicate’ doesn’t work for 3d images it seems.
I can’t access my code right now, but I think I tried to programm it manually like this with a,b,c being the count of lines to be padded on:

shape = img.shape
img_padded = F.pad(img, (0, a, 0, b, 0, c))
#1) replication on first dimension seems to work fine like this
img_padded[shape[0]:, :shape[1], :shape[2]] = img_padded[shape[0]-1, :shape[1], :shape[2]]
#2) this doesn’t work anymore though
img_padded[:, shape[1]:, :shape[2]] = img_padded[:, shape[1]-1, :shape[2]]
img_padded[:, :, shape[2]:] = img_padded[:, :, shape[2]-1]

What I really don’t get is why it works for 1) and not for 2). I could understand why it would not work like this at all though.
Anyway, is there any nice solution to do replication or reflection padding in 3 dimensional images?