[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