I want to make convolution of matrix
np.random.seed(0)
m_numpy = np.random.choice([0,1],p=(0.5,0.5),size=(6,6))
m = torch.from_numpy(Z_numpy).type(torch.FloatTensor)
tensor([[1., 1., 1., 1., 0., 1.],
[0., 1., 1., 0., 1., 1.],
[1., 1., 0., 0., 0., 1.],
[1., 1., 1., 1., 0., 1.],
[0., 1., 0., 1., 1., 0.],
[0., 1., 0., 1., 0., 1.]])
with kernel:
krnl = torch.tensor([[1,1,1],
[1,0,1],
[1,1,1]])
krnl
tensor([[1, 1, 1],
[1, 0, 1],
[1, 1, 1]])
However using function conv2d
from torch.nn.functional
I don't see where to write those tensors in it. Doing this conv2d(m, krnl,mode='same')
brings error:
TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Tensor, mode=str), but expected one of:
* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
* (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
How to do that?