I was wondering if you could help me define a torch.nn.ReflectionPad3d layer?
I only found this post:
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.

Found the answer in the following link:
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