简体   繁体   English

使用卷积自动编码器从2D到3D

[英]From 2D to 3D using convolutional autoencoder

I'd like to reconstruct 3D object from 2D images. 我想从2D图像重建3D对象。 For that, I try to use convolutional auto encoder. 为此,我尝试使用卷积自动编码器。 However, in which layer should I lift the dimensionality? 但是,我应该在哪一层提升尺寸?

I wrote a code below, however, it shows an error: 我在下面编写了代码,但是显示错误:

“RuntimeError: invalid argument 2: size '[1 x 1156 x 1156]' is invalid for input of with 2312 elements at pytorch-src/torch/lib/TH/THStorage.c:41” “ RuntimeError:无效参数2:大小'[[1 x 1156 x 1156]”对于在pytorch-src / torch / lib / TH / THStorage.c:41中输入2312个元素无效”

class dim_lifting(nn.Module):
    def __init__(self):
        super(dim_lifting, self).__init__()
        self.encode = nn.Sequential(
            nn.Conv2d(1, 34, kernel_size=5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(34, 16, kernel_size=5, padding=2),
            nn.MaxPool2d(2),
            nn.Conv2d(16, 8, kernel_size=5, padding=2),
            nn.MaxPool2d(2),
            nn.LeakyReLU()
        )

        self.fc1 = nn.Linear(2312, 2312)
        self.decode = nn.Sequential(
            nn.ConvTranspose3d(1, 16, kernel_size=5, padding=2),
            nn.LeakyReLU(),
            nn.ConvTranspose3d(16, 32, kernel_size=5, padding=2),
            nn.LeakyReLU(),
            nn.MaxPool2d(2))

    def forward(self, x):
        out = self.encode(x)
        out = out.view(out.size(0), -1)
        out = self.fc1(out)
        out = out.view(1, 1156, 1156)
        out = self.decode(out)
        return out

Error happens here 错误发生在这里

out = out.view(1, 1156, 1156)

I cannot test my suggestion because your example is not complete. 我无法验证我的建议,因为您的示例不完整。 I think your line should like 我想你的电话应该喜欢

out = out.view(x.size(0), -1)

this way you're flattening out your input. 这样,您就可以简化您的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM