Is there a nn.padding of Torch in PyTorch?

I would like to use a padding module which is already implemented in Torch (nn.Padding), but I get an error message when I use the padding module which exists in torch.legacy.nn:

TypeError: ‘Padding’ object is not callable

Does anyone know how to use this? Or is there a module which can replace it?

How did you import the legacy package? It works for me

I used the code similar to the one below:

import torch
import torch.legacy.nn as L
pad = L.Padding(1,2)
output = pad(torch.randn(1,3,4,4))

legacy package does not have a call operator. You need to do: pad = L.Padding.forward(1, 2). Legacy package is EXACTLY like in LuaTorch

1 Like

if My input is cuda tensor. How I can do it ,It seems that the L.Padding.forward()only support CPU tensor.

1 Like

Probably L.Padding(1, 2).cuda().forward(x)

1 Like