Calculate dim of fully connected layer in a CNN

Greetings,

I understand the underlying concept about calculating dimensions from a fully connected layer in a CNN. However, i am wondering if there is a smarter way to compute those.I mean, in a big network, it is a pain to calculate these dimensions. Please advice.

By fully conected layer in a cnn,i mean:

        self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
-->> self.fc1 = nn.Linear(320, 50)
        self.fc2 = nn.Linear(50, 10)

The easy approach would be to print the shape of the incoming activations first and set the in_features of the first linear layer afterwards. Alternatively, you could use the Lazy* layers, which would set the input shape for you.