[Pytorch] 卷積尺寸計算


公式來自官方文檔,戳->(Conv3d — PyTorch master documentation
本文僅作記錄,順便練習Latex語法

2D

\(H_{out}=\frac{H_{in}+2\times padding[0]-dilation[0]\times(kernel\_size[0]-1)-1}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}+2\times padding[1]-dilation[1]\times(kernel\_size[1]-1)-1}{stride[2]}+1\)

如果默認dilation=1的話:

\(H_{out}=\frac{H_{in}+2\times padding[0]-kernel\_size[0]}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}+2\times padding[1]-kernel\_size[1]}{stride[2]}+1\)

如果默認dilation=1, stride=1的話:

\(H_{out}=H_{in}+2\times padding[0]-kernel\_size[0]+1\)
\(W_{out}=W_{in}+2\times padding[1]-kernel\_size[1]+1\)

如果默認dilation=1, stride=1, padding=0的話:

\(H_{out}=H_{in}-kernel\_size[0]+1\)
\(W_{out}=W_{in}-kernel\_size[1]+1\)

如果默認dilation=1, padding=0的話:

\(H_{out}=\frac{H_{in}-kernel\_size[0]}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}-kernel\_size[1]}{stride[2]}+1\)

3D

\(D_{out}=\frac{D_{in}+2\times padding[0]-dilation[0]\times(kernel\_size[0]-1)-1}{stride[0]}+1\)
\(H_{out}=\frac{H_{in}+2\times padding[1]-dilation[1]\times(kernel\_size[1]-1)-1}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}+2\times padding[2]-dilation[2]\times(kernel\_size[2]-1)-1}{stride[2]}+1\)

如果默認dilation=1的話:

\(D_{out}=\frac{D_{in}+2\times padding[0]-kernel\_size[0]}{stride[0]}+1\)
\(H_{out}=\frac{H_{in}+2\times padding[1]-kernel\_size[1]}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}+2\times padding[2]-kernel\_size[2]}{stride[2]}+1\)

如果默認dilation=1, stride=1的話:

\(D_{out}=D_{in}+2\times padding[0]-kernel\_size[0]+1\)
\(H_{out}=H_{in}+2\times padding[1]-kernel\_size[1]+1\)
\(W_{out}=W_{in}+2\times padding[2]-kernel\_size[2]+1\)

如果默認dilation=1, stride=1, padding=0的話:
\(D_{out}=D_{in}-kernel\_size[0]+1\)
\(H_{out}=H_{in}-kernel\_size[1]+1\)
\(W_{out}=W_{in}-kernel\_size[2]+1\)

如果默認dilation=1, padding=0的話:

\(D_{out}=\frac{D_{in}-kernel\_size[0]}{stride[1]}+1\)
\(H_{out}=\frac{H_{in}-kernel\_size[1]}{stride[1]}+1\)
\(W_{out}=\frac{W_{in}-kernel\_size[2]}{stride[2]}+1\)

附用法

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', 'reflect', 'replicate' or 'circular'. Default: 'zeros'
dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1
groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1
bias (bool, optional) – If True, adds a learnable bias to the output. Default: True


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM