在 PyTorch 中,当我有 padding 时,我的 Conv1d 尺寸如何减少?

问题描述 投票:1回答:1

我的 conv module 是。

        return torch.nn.Sequential(
            torch.nn.Conv1d(
                in_channels=in_channels,
                out_channels=in_channels,
                kernel_size=2,
                stride=1,
                dilation=1,
                padding=1
            ),
            torch.nn.ReLU(),
            torch.nn.Conv1d(
                in_channels=in_channels,
                out_channels=in_channels,
                kernel_size=2,
                stride=1,
                dilation=2,
                padding=1
            ),
            torch.nn.ReLU(),
            torch.nn.Conv1d(
                in_channels=in_channels,
                out_channels=in_channels,
                kernel_size=2,
                stride=1,
                dilation=4,
                padding=1
            ),
            torch.nn.ReLU()
        )

而在... forward,我有。

down_out = self.downscale_time_conv(inputs)

inputs 有一个 .sizetorch.Size([8, 161, 24]). 我希望 down_out 有相同的大小,但它有。torch.Size([8, 161, 23])

最后一个元素去哪了?

python pytorch tensor
1个回答
3
投票

答案可以在网上的Pytorch文档中找到 (此处). 对于每一个操作,输出形状都是相对于输入参数来表示的。

enter image description here

对于每个conv1D,

- L1 = 25 → int((24 + 2*1 - 1*(2 - 1) - 1) / 1 + 1)
- L2 = 25 → int((25 + 2*1 - 2*(2 - 1) - 1) / 1 + 1)
- L3 = 23 → int((25 + 2*1 - 4*(2 - 1) - 1) / 1 + 1)

不要忘记 Lin 是以前的大小。

© www.soinside.com 2019 - 2024. All rights reserved.