Deep Learning with PyTorch: A 60 Minute Blitz
书接上回,了解了PyTorch的自动求导(autograd)过程后,尝试搭建简单的卷积神经网络;
这里直接摆上tutorials的CNN代码,并对其中一些点进行强调和补充;
import torch
import torch.nn as nn
import torch.nn.functional as F
1. torch.nn
torch.nn包中汇集了神经网络中常用的层模块:
卷积层(torch.nn.Conv2d)
CLASS torch.nn.
Conv2d
(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros')
Parameters
in_channels (int) – Number of channels in the input image
out_channels (int) – Number of channels produced by the convolution
kernel_size (int or tuple) – Size of the convolving kernel
stride (int or tuple, optional) – Stride of the convolution. Default: 1
padding (int or tuple, optional) – Zero-padding added to both sides of the input. Default: 0
padding_mode (string, optional) – zeros
dilation (int or