PyTorch深度学习实践(10. Basic CNN-1)

源自课程:《PyTorch深度学习实践》完结合集

Chapter10 卷积神经网络(基础篇)

# 代码片段

"""
基础卷积神经网络CNN
"""
import torch

# 预设参数
in_channel, out_channels = 5, 10
width, height = 100, 100
kernel_size = 3
batch_size = 1

# 注意:在pytorch中是b,in,h,w
input = torch.randn(batch_size,
                    in_channel,
                    height,
                    width)

# 二维卷积层
conv_layer = torch.nn.Conv2d(in_channel,
                             out_channels,
                             kernel_size=kernel_size,
                             padding=1)

# 输出结果
output = conv_layer(input)


# 打印输出形状
print(input.shape)
print(output.shape)
print(conv_layer.weight.shape)

你可能感兴趣的:(深度学习,pytorch,人工智能)