【发布时间】:2021-10-03 12:33:56
【问题描述】:
我想对矩阵进行卷积
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.]])
带内核:
krnl = torch.tensor([[1,1,1],
[1,0,1],
[1,1,1]])
krnl
tensor([[1, 1, 1],
[1, 0, 1],
[1, 1, 1]])
但是使用来自torch.nn.functional 的函数conv2d 我看不到在哪里写这些张量。这样做conv2d(m, krnl,mode='same') 会带来错误:
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)
怎么做?
【问题讨论】:
标签: python pytorch convolution