To pad a given with a custom number, you will have to use the functionality torch.nn.functional.pad() mentioned in the docs here.
A simple implementation can be:
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
# pads with custom float value and then performs 3d convolution
# no padding at convolution step
self.conv1 = nn.Conv3d(3, 16, 3, stride=2, padding=0)
self.p3d = (1, 1, 1, 1, 1, 1) # pad by (1, 1), (1, 1), and (1, 1)
def forward(self, x):
#p3d is dimensions to pad, constant means constant value padding, and 0 is the number you want to pad with
x = torch.nn.functional.pad(x, self.p3d, "constant", 0)
x = self.conv1(x)
return x
This way you can pad with any custom number you want.