Printing out model summary

I’m trying to print model summary out so I can see how the image size changes as it goes through convolutions. I read that I can get a print out similar to Keras’ model.summary(), by installing torchsummary and using it. So,

!pip install torchsummary 
from torchsummary import summary
summary(gen, input_size = (1,64))

And I get an error:
RuntimeError: shape '[2, 10, 1, 1]' is invalid for input of size 128 pretty much no matter what input size I pass through. So my question is, what should be the correct input_size here. Is there a better way to print a model summary?

Thanks!

Hi, @mazatov !

That is the way you should use torchsummary. Sometimes it does not work with pretty complex layers. Try printing the model directly or with another third party package.

Hey @alvaroramajo ,

I got it to work for the generator model. And I am a bit confused by the last layer. It looks like we transition from [-1, 64, 31, 31] to [-1, 3, 64, 64] using nn.ConvTranspose2d(64, 3, 4, 2).

So in this case the output image dimension is only characterized by the number of self.make_gen_block in the model. So to get to 64x64 we had 5 blocks. Am I correct? I feel like I missed that in the instructions somewhere and was expecting the output dimension be somehow passed to the model.

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
   ConvTranspose2d-1            [-1, 512, 3, 3]         295,424
       BatchNorm2d-2            [-1, 512, 3, 3]           1,024
              ReLU-3            [-1, 512, 3, 3]               0
   ConvTranspose2d-4            [-1, 256, 7, 7]       1,179,904
       BatchNorm2d-5            [-1, 256, 7, 7]             512
              ReLU-6            [-1, 256, 7, 7]               0
   ConvTranspose2d-7          [-1, 128, 15, 15]         295,040
       BatchNorm2d-8          [-1, 128, 15, 15]             256
              ReLU-9          [-1, 128, 15, 15]               0
  ConvTranspose2d-10           [-1, 64, 31, 31]          73,792
      BatchNorm2d-11           [-1, 64, 31, 31]             128
             ReLU-12           [-1, 64, 31, 31]               0
  ConvTranspose2d-13            [-1, 3, 64, 64]           3,075
             Tanh-14            [-1, 3, 64, 64]               0
================================================================
Total params: 1,849,155
Trainable params: 1,849,155
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.00
Forward/backward pass size (MB): 2.65
Params size (MB): 7.05
Estimated Total Size (MB): 9.70
----------------------------------------------------------------