代码之家  ›  专栏  ›  技术社区  ›  Tom Hale

Pythorch:获取输入层大小

  •  -1
  • Tom Hale  · 技术社区  · 6 年前

    我想通过编程找到输入层的大小。

    如果我的第一层 fc1

    1 回复  |  直到 6 年前
        1
  •  2
  •   Tom Hale    6 年前

    假设您的模型名为 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
        ...