Number of input for linear layer

Hi, I am building a network containing a linear layer at the top of my architecture.
I notice that the number of input units need to be explicitly specified like:
self.fc1 = nn.Linear(5033, 30)
I know I can compute the number of output from my previous pooling layer. I was wondering if there is a more convenient way to define a network without computing number of units for each layer.

Thanks in advance

No, we require providing the exact numbers of features at construction time. I think it’s safer and you gain more insight into your network structure, because you know exactly what kind of dimensionalities are used. If it’s really unacceptable for you, you might create the layers lazily in the forward function, but that’s not recommended.

1 Like

OK, that is clear.
Thanks so much for your quick reply.