import torch
in_channels,out_channels=5,10 #in 决定卷积核的channel;out 决定卷积核的个数
width,hight=100,100
kernel_size=3 #卷积核的边长 卷积核一般为奇数边长正方形
batch_size=1
input=torch.randn(batch_size, #random normal
in_channels,
hight,
width) #torch中输入必须含有批量 即输入数据为4维张量 (b*c*h*w)
conv_layer=torch.nn.Conv2d(in_channels, #定义卷积层
out_channels,
kernel_size=kernel_size) #定义卷积层的四个值(四维张量)
output=conv_layer(input)
print(input.shape)
print(output.shape)
print(conv_layer.weight.shape)
卷积神经网络:定义卷积层
最新推荐文章于 2024-05-25 21:32:01 发布