规定矩阵输入必须是(N,C,H,W)形式,N代表batch size,C代表channel
input = torch.Tensor([[1,2,0,3,1],
[0,1,2,3,1],
[1,2,1,0,1],
[5,3,4,2,1],
[2,1,0,1,1]])
kernel = torch.Tensor([[0,1,1],
[0,1,0],
[1,0,1]])
print(input.shape)
将矩阵变换成1个batch,1通道,5*5的尺寸
input =torch.reshape(input,(1,1,5,5))
torch.reshape(kernel,(1,1,3,3))
print(input.shape)
CLASS torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros',
device=None, dtype=None)