self.encoder uses a nn.Conv2d as the first layer, which expects an input with the shape [batch_size, channels, height, width], while you are flattening your input tensor in the first step via x = x.view(x.size(0), -1).
If you remove the view op, the first layers will run, but you will run into another shape mismatch error passing the activation to the nn.Linear layer.
Add an nn.Flatten() module before the first nn.Linear and rerun the code again.