二维卷积可以处理二维数据
import torch import torch.nn as nn x = torch.randn(10, 16, 30, 32) # batch, channel , height , width print(x.shape) m = nn.Conv2d(16, 33, (3, 2), (2,1)) # in_channel, out_channel ,kennel_size,stride print(m) y = m(x) print(y.shape)
torch.Size([10, 16, 30, 32]) Conv2d(16, 33, kernel_size=(3, 2), stride=(2, 1)) torch.Size([10, 33, 14, 31])
h = floor((h - kennel_size + 2*padding) / stride )+ 1,w同理
x = ([10,16,30,32]),其中h=30,w=32,对于卷积核长分别是 h:3,w:2 ;对于步长分别是h:2,w:1;padding默认0;
h = (30 - 3 + 20)/ 2 +1 = 27/2 +1 = 13+1 =14
w =(32 - 2 + 2*0)/ 1 +1 = 30/1 +1 = 30+1 =31
batch = 10, out_channel = 33
故: y= ([10, 33, 14, 31])
原文:https://www.cnblogs.com/tingtin/p/13547365.html