pytorch nn.Conv2d()中的padding以及输出大小

 

 

conv1=nn.Conv2d(1,2,kernel_size=3,padding=1)
conv2=nn.Conv2d(1,2,kernel_size=3)

inputs=torch.Tensor([[[[1,2,3],
                     [4,5,6],
                     [7,8,9]]]])
print("input size: ",inputs.shape)
outputs1=conv1(inputs)
print("output1 size: ",outputs1.shape)
outputs2=conv2(inputs)
print("output2 size: ",outputs2.shape)

输出:
input size:  torch.Size([1, 1, 3, 3])
output1 size:  torch.Size([1, 2, 3, 3])
output2 size:  torch.Size([1, 2, 1, 1])

padding是指卷积前进行padding,这样保证输出的图像形状大小与输入相同,但是通道数channel改变了。

你可能感兴趣的:(小知识点)