As far as I know, the size mismatch always comes from the network architecture like the number of convolution which not have the required size. My suggestion you can go to your network code. From your code I see output = sae(input) . You can see in class sae and check the size for every layer.