Writing a Padding Function

I received a task on one of the platforms, it is necessary to manually implement padding with 1 layer 0 around each of the layers of the image channel. I tried everything already, but I didn’t have enough knowledge (
Please help me decide.

input_images = torch.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, 32],
         [33, 34, 35]],

        [[36, 37, 38],
         [39, 40, 41],
         [42, 43, 44]],

        [[45, 46, 47],
         [48, 49, 50],
         [51, 52, 53]]]])
def get_padding2d(input_images):
    padded_images= #here
    return padded_images

I’m quite sure I understand your use case wrong, but in case you want “standard” padding in the spatial dimensions, this should work:

output = F.pad(input_images, [1, 1, 1, 1])

If that’s not your use case, could you print the desired output, please?