torch.nn.ReflectionPad3d?

I was wondering if you could help me define a torch.nn.ReflectionPad3d layer?
I only found this post:
https://discuss.pytorch.org/t/reflectionpad3d/20403
And the answer doesn’t make any sense. Thank you.

Even this answer doesn’t work correctly, since this ReflectionPadNd function does not work correctly.
https://github.com/c22n/unet-pytorch/blob/master/models/custom_layers.py

Found the answer in the following link:
https://discuss.pytorch.org/t/how-to-pad-one-side-in-pytorch/21212/2
torch.nn.functional.pad ( input, pad , mode='reflect' , value=(1, 1, 1, 1, 1, 1) ) will do the job. Can be rapped around a module as well:

import torch
import torch.nn.functional as F

class CustomPad(torch.nn.module):
  def __init__(self, padding):
    self.padding = padding
  def forward(self, x):
    return F.pad(x. self.padding, mode='reflect')
1 Like