height和width的变化有些疑问,迷惑中,记录下

摸了摸语义分割SegNet,对于维度的变换有些卡住,这里记录下。

根据torch.nn内的conv2d的定义,

\(C_{out}\)\(H_{out}, W_{out}\) 的变化规则:
Shape:
Input: :math:\((N, C_{in}, H_{in}, W_{in})\)
Output: :math:\((N, C_{out}, H_{out}, W_{out})\) where
$$
H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[0] - \text{dilation}[0] \times (\text{kernel_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor
$$
$$
W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[1] - \text{dilation}[1] \times (\text{kernel_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor
$$

>>> input = torch.randn(1,3,256,256)
>>> m = nn.Conv2d(3,64,3)
>>> out = m(input)
>>> input.shape
torch.Size([1, 3, 256, 256])
>>> out.shape
torch.Size([1, 64, 254, 254])

\(H_{in}=256\) 带入式子里,最后的结果是254,按理说是255. 迷惑中,记录下.

posted @ 2022-11-20 20:03  菠菜火锅  阅读(15)  评论(0编辑  收藏  举报