Meaning of output shapes of ResNet9 model layers

I have a ResNet 9 model, implemented in Pytorch which I am using for multi-class image classification. My total number of classes is 6. Using the following code, from torchsummary library, I am able to show the summary of the model, seen in the attached image:

INPUT_SHAPE = (3, 256, 256) #input shape of my image
print(summary(model.cuda(), (INPUT_SHAPE)))

However, I am quite confused about the -1 values in all layers of the ResNet9 model. Also, for Conv2d-1 layer, I am confused about the 64 value in the output shape [-1, 64, 256, 256] as I believe the n_channels value of the input image is 3. Can anyone please help me with the explanation of the output shape values? Thanks!

summary expects the first dimension to be the batch dimension and thus “dynamic”. Instead of printing a fixed batch size, they just print -1 instead.

nn.Conv2d layer define the in_channels as the number of channels of the input activation and out_channels as the number of channels of the output activation (and thus the number of filters) which is set to 64 in the first conv layer.

1 Like

Thanks a lot for your help @ptrblck. Also, can it be said that Conv2d-1, BatchNorm2d-2 and ReLU-3 consist of the input layer of the network?

Most likely Conv2d-1 would be the input layer to the model, but I don’t know how exactly summary creates the order of modules.
E.g. using the order of module initialization could be wrong, since you can use any order to initialize the modules in the __init__ method and use another order in the forward.
The safest approach would be to check the forward method directly and see which layer is used first.

1 Like

I’ll try that, thanks a lot.