像这样使用PyTorch的ConvTranspose2d时:
w = 5 # input width
h = 5 # output height
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=k, stride=s, padding=p)
每个通道中输出尺寸的公式是什么?我尝试了一些示例,但无法得出模式。由于某种原因,添加填充似乎会缩小输出大小(示例从上述的5 x 5开始):
# yields an 11 x 11 image
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=3, stride=2, padding=0)
# yields a 7 x 7 image
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=3, stride=2, padding=2)
使用更大的内核或步幅都增加(预期),但没有达到我期望的速度:
# yields an 11 x 11 image
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=3, stride=2, padding=0)
# yields a 13 x 13 image
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=5, stride=2, padding=0)
# yields a 15 x 15 image
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=3, stride=3, padding=0)
我肯定有一个涉及w, h, k, s, p
的非常简单的数学方程式,但是我在文档中找不到它,而且我自己也无法导出它。通常,我不会要求数学方程式,但是它完全影响了CNN编译和生成正确大小的能力。预先感谢!
答案 0 :(得分:0)
documentation页面上提到了计算ConvTranspose2d
输出大小的公式:
H_out =(H_in-1)*步幅[0] − 2×padding [0] +膨胀[0]×(kernel_size [0] −1)+ output_padding [0] +1
W_out =(Win−1)×步幅[1]-2×padding [1] +膨胀[1]×(kernel_size [1] −1)+ output_padding [1] + 1
默认情况下,步幅= 1,padding = 0,output_padding = 0。
例如,对于
nn.ConvTranspose2d(in_channels, out_channels, kernel_size=3, stride=2, padding=0)
H_out
将
H_out = (5-1)*2 - 2*0 + 1*(3-1) + 0 + 1 = 11