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.