zl程序教程

您现在的位置是:首页 >  其它

当前栏目

torch.nn.Conv2d()使用

torch NN 使用
2023-09-11 14:17:14 时间

API

输入:[ batch_size, channels, height_1, width_1 ]

Conv2d输入参数:[ channels, output, height_2, width_2 ]

输出:[ batch_size,output, height_3, width_3 ]

 

实例:

def torch_practice():
    x = torch.randn(2,1,16,4)
    conv = torch.nn.Conv2d(1, 32, (2,2))
    res = conv(x)
    print(res.shape)


if __name__ == '__main__':
    torch_practice()

输出:torch.Size([2, 32, 15, 3])

batch大小不变:2

输出通道加厚:32。由卷积核的通道数决定

卷积结果:[15,3]。计算公式,n-m+1, 16-2+1=15