0

I’d like to reconstruct 3D object from 2D images. 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”

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)
Manuel Lagunas
  • 2,611
  • 19
  • 31
soshi shimada
  • 425
  • 1
  • 7
  • 21
  • Are you sure that the dimensions specified in `out = out.view(1, 1156, 1156)` are correct? It seems like you cannot fit an input with 2312 elements in 1*1156*1156=1336336 – Manuel Lagunas Nov 19 '17 at 11:58

1 Answers1

1

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.

Wasi Ahmad
  • 35,739
  • 32
  • 114
  • 161
Harry Yoo
  • 341
  • 2
  • 9