Solved by ptrblck in post #4 
              
              
                The new error doesn’t seem to be an equivalent error, since the forward pass is failing due to an expected shape mismatch in the Encoder. 
Change: 
nn.Linear(2*16*c_hid, latent_dim)

to 
nn.Linear(41216, latent_dim)

and the model works for me: 
num_input_channels, width, height = 182, 218, 182     …