PyTorch:获取输入图层大小

时间:2018-11-26 06:10:28

标签: pytorch

我想以编程方式找到输入层的大小。

如果我的第一层称为fc1,如何查找其输入?

1 个答案:

答案 0 :(得分:0)

假设您的模型名为model,这将提供fc1层的输入特征数:

model.fc1.in_features

这在.forward()方法中很有用:

def forward(self, x):
    x = x.view(-1, self.fc1.in_features)  # resize the input to match the input layer
    ...
相关问题