I am trying to do padding a 2D matrix, when I use ConstantPad2d, it works fine for 4D but it is not working for 3D/2D.
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch import autograd



input = autograd.Variable(torch.randn(1,1,3, 3))

m = nn.ConstantPad2d((1,1,1,1), 0)
output = m(input)
print(output)

Can anyone help me here.
I tried the other methods in the forum but couldn’t make them work.
basically this does not work:
input = autograd.Variable(torch.randn(3, 3))

m = nn.ConstantPad2d((1,1,1,1), 0)
output = m(input)
print(output)