'How to fix error with pytorch conv2d function?

I am trying to use conv2d function on these two tensors:

Z = np.random.choice([0,1],size=(100,100))
Z = torch.from_numpy(Z).type(torch.FloatTensor)

print(Z)

tensor([[0., 0., 1.,  ..., 1., 0., 0.],
        [1., 0., 1.,  ..., 1., 1., 1.],
        [0., 0., 0.,  ..., 0., 1., 1.],
        ...,
        [1., 0., 1.,  ..., 1., 1., 1.],
        [1., 0., 1.,  ..., 0., 0., 0.],
        [0., 1., 1.,  ..., 1., 0., 0.]

and

filters = torch.tensor(np.array([[1,1,1],
                        [1,0,1],
                        [1,1,1]]), dtype=torch.float32)

print(filters)

tensor([[1., 1., 1.],
        [1., 0., 1.],
        [1., 1., 1.]])

But when I try to do torch.nn.functional.conv2d(Z,filters) this error returns:

RuntimeError: weight should have at least three dimensions

I really don't understand what is the problem here. How to fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source