pytorch 学习笔记 part8 卷积神经网络基础

Bianca ·
更新时间:2024-11-13
· 794 次阅读

卷积层的实现

主要参数:
1.in_channels (python:int) – Number of channels in the input imag
2.out_channels (python:int) – Number of channels produced by the convolution
3.kernel_size (python:int or tuple) – Size of the convolving kernel
4.stride (python:int or tuple, optional) – Stride of the convolution. Default: 1
5.padding (python:int or tuple, optional) – Zero-padding added to both sides of the input. Default: 0
6.bias (bool, optional) – If True, adds a learnable bias to the output. Default: True

X = torch.rand(4, 2, 3, 5) print(X.shape) conv2d = nn.Conv2d(in_channels=2, out_channels=3, kernel_size=(3, 5), stride=1, padding=(1, 2)) Y = conv2d(X) print('Y.shape: ', Y.shape) print('weight.shape: ', conv2d.weight.shape) print('bias.shape: ', conv2d.bias.shape) 池化层的实现

主要参数:

1.kernel_size – the size of the window to take a max over
2.stride – the stride of the window. Default value is kernel_size
3.padding – implicit zero padding to be added on both sides

X = torch.arange(32, dtype=torch.float32).view(1, 2, 4, 4) pool2d = nn.MaxPool2d(kernel_size=3, padding=1, stride=(2, 1)) Y = pool2d(X) print(X) print(Y)
作者:符尔摩斯



网络基础 part 学习笔记 pytorch 学习 卷积神经网络 神经网络 卷积

需要 登录 后方可回复, 如果你还没有账号请 注册新账号