卷积神经网络:卷积层参数padding(填充)

import torch
input=[1,2,3,4,5,
       6,7,8,9,9,
       1,2,3,4,5,
       6,7,8,9,9,
       1,2,3,4,5]
#ToTensor
input=torch.Tensor(input).view(1,1,5,5) #(b*c*h*w)
#定义卷积层
conv_layer=torch.nn.Conv2d(in_channels=1,
                           out_channels=1,
                           kernel_size=3,
                           padding=1,#在input的四周填充一层
                           bias=False)
#构建卷积核(卷积层的权重值)
kernel=torch.Tensor([1,2,3,4,5,6,7,8,9]).view(1,1,3,3)

conv_layer.weight.data=kernel.data

output=conv_layer(input)
print(output)

猜你喜欢

转载自blog.csdn.net/qq_21686871/article/details/114293014