The output of the 2nd conv layer in self.encoder will have the shape [batch_size, 128, 7, 7] for an input of [batch_size, 19, 28, 28] and the Flatten() layer will thus create an activation of [batch_size, 6272], which doesn’t fit the expected 80000 input features in the following linear layer.