Pytorch:Conv2d卷积前后尺寸详解
Pytorch:Conv2d卷积前后尺寸
Conv2d参数
尺寸变化
卷积前的尺寸为(N,C,W,H) ,卷积后尺寸为(N,F,W_n,H_n)
- W_n = (W-F+S+2P)/S 向下取整
- H_n = (H-F+S+2P)/S
示例
# m = nn.Conv2d(16, 33, 3, stride=2)
# non-square kernels and unequal stride and with padding
m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
# non-square kernels and unequal stride and with padding and dilation
# m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1))
input = torch.randn(20, 16, 50, 100)
print(input.size())
output = m(input)
print(output.size())
反卷积(转置卷积)Conv2DTranspose 输出的尺寸大小
keras的Conv2DTranspose
The size of the input feature map: (N, N)
Conv2dTranspose(kernel_size=k, padding, strides=s)
padding=‘same' ,输出尺寸 = N × s
padding=‘valid',输出尺寸 = (N-1) × s + k
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
相关文章