首页 > 解决方案 > 如何在卷积自动编码器中使用 pytorch 库中的 MaxUnpool1d?

问题描述

我想在 python 中使用 Pytorch 库构建一个卷积自动编码器。所有示例都没有 MaxUnpool1d。

我要构建的架构应该是这样的:

class autoencoder(nn.Module):
    def __init__(self):
            self.encoder = nn.Sequential(
                                 nn.Conv1d(in_channels=1, out_channels=64 ,kernel_size=16 , stride=3),
                                 nn.ReLU(True),
                                 nn.MaxPool1d(4),
                                 nn.Conv1d(64, 128 ,8, 3),
                                 nn.ReLU(True),
                                 nn.MaxPool1d(4), 
                                 )

            self.decoder = nn.Sequential(
                                 nn.MaxUnpool1d(4),
                                 nn.ConvTranspose1d(in_channels =128, out_channels =64 , kernel_size =8, stride= 3),
                                 nn.ReLU(True),
                                 nn.MaxUnpool1d(4),
                                 nn.ConvTranspose1d(64, 1 ,16, 3),
                                 nn.Tanh()
                                 )

    def forward(self, x):
        x = self.encoder(x)
        x = self.decoder(x)
        return x

为了让它工作,我应该为 MaxUnpool1d 层提供索引。如何在当前架构中使用它并使输入大小等于输出?

谢谢。

标签: pythonmachine-learningdeep-learningpytorchautoencoder

解决方案


推荐阅读