咱们简单说一下卷积核,通过一系列的输入数据,通过卷积核进行计算,按照特定的方式进行输出,达到预期的结果。
input-----卷积核------output
咱们做一下矩阵的卷积。
import torch
import torch.nn.functional as F
input=torch.tensor([[1,2,1,3,1],
[0,1,2,3,1],
[1,2,3,0,5],
[5,2,6,1,1,],
[2,1,3,4,1]])
kernel=torch.tensor([[1,2,1],
[2,1,3],
[2,1,1]])
input=torch.reshape(input,(1,1,5,5))
kernel=torch.reshape(kernel,(1,1,3,3))
output=F.conv2d(input,kernel,stride=1)
print(output)
结果如下: