Shape of the input

I have MNIST images [shape:100*784 (batch size is 100)]
and after my first encoder, output shape is 100 * 120.
With this output I want forward to this second encoder.
but RuntimeError: Expected 4-dimensional input for 4-dimensional weight occurs.

Do I have to reshape 100*120 -> something 4-dimensional ? or anyway to solve this error?

> class Encoder(nn.Module):
>     def __init__(self):
>         super(Encoder, self).__init__()
>         self.extractor1 = nn.Sequential(
>             nn.Conv2d(in_channels=1, out_channels=64, kernel_size=5, stride=1, padding=2),
>             nn.BatchNorm2d(64),
>             nn.ReLU(True),
>             nn.MaxPool2d(kernel_size=2),
>         )
> 
>     def forward(self, x):
>         x = self.extractor1(x)
>         x = x.view(-1, out_size)
>         return x

The encoder you’ve posted is using a conv layer, which expects 4-dimensional input, i.e. [batch_size, channels, height, width].
In the forward you are flattening x, which yields a tensor of shape [batch_size, out_size].
If your second encoder also uses a conv layer at the beginning, just remove the flattening operation and return the output directly.