@lfolle  That will be good for a fixed number of convolution layers and I, ultimately, will have to calculate for every layer which is not required.
The code needs to be robust and hence, need a general solution for the problem which can be applied to any number of convolutional layers.