PyTorch
PyTorch相关笔记
输出大小计算
卷积层
1
nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding)
输入大小为$W \times H \times D$(宽度、高度和深度),卷积核大小为$K_w \times K_h$ ,步幅(stride)为$S_w$和$S_h$,填充(padding)为$P_w$和$P_h$,输出深度(输出通道数)为$D_{out}$
输出宽度$W_{out}$:
\(W_{out} = \left\lfloor \frac{W - K_w + 2P_w}{S_w} \right\rfloor + 1\)输出高度$H_{out}$:
\(H_{out} = \left\lfloor \frac{H - K_h + 2P_h}{S_h} \right\rfloor + 1\)输出深度$D_{out}$等于卷积核的个数(输出通道数)
池化层
最大值池化
1
nn.MaxPool2d(kernel_size, stride, padding, dilation)
输入大小为$W \times H \times D$(宽度、高度和深度),卷积核大小为$K_w \times K_h$ ,步幅(stride)为$S_w$和$S_h$,填充(padding)为$P_w$和$P_h$,膨胀(dilation)为$D_w$和$D_h$
输出宽度$W_{out}$:
\(W_{out} = \left\lfloor \frac{W + 2P_w - D_w \cdot (K_w - 1) - 1}{S_w} \right\rfloor + 1\)输出高度$H_{out}$:
\(H_{out} = \left\lfloor \frac{H + 2P_h - D_h \cdot (K_h - 1) - 1}{S_h} \right\rfloor + 1\)输出深度$D_{out}$等于输入深度$D$
平均值池化
1
nn.AvgPool2d(kernel_size, stride, padding)
输入大小为$W \times H \times D$(宽度、高度和深度),卷积核大小为$K_w \times K_h$ ,步幅(stride)为$S_w$和$S_h$,填充(padding)为$P_w$和$P_h$
输出宽度$W_{out}$:
\(W_{out} = \left\lfloor \frac{W + 2P_w - K_w}{S_w} \right\rfloor + 1\)输出高度$H_{out}$:
\(H_{out} = \left\lfloor \frac{H + 2P_h - K_h}{S_h} \right\rfloor + 1\)输出深度$D_{out}$等于输入深度$D$
自适应最大值池化
1
nn.AdaptiveAvgPool2d(output_size)
输入大小为$W \times H \times D$(宽度、高度和深度),目标输出大小为$W_{out} \times H_{out} \times D_{out}$
输出宽度$W_{out}等于指定的目标宽度
输出高度$H_{out}等于指定的目标高度
输出深度$D_{out}$等于输入深度$D$