Reputation: 46715
I want to programatically find the size of my input layer.
If my first layer is called fc1
, how do I find out its input?
Upvotes: 5
Views: 4702
Reputation: 46715
Assuming your model is called model
, this will give the number of input features of the fc1
layer:
model.fc1.in_features
This is useful inside the .forward()
method:
def forward(self, x):
x = x.view(-1, self.fc1.in_features) # resize the input to match the input layer
...
Upvotes: 4