pytorch输出网络结构

输出网络结构

如果要查看网络的网络结构,可以使用_modules属性

model._modules
OrderedDict([('conv1',
              Sequential(
                (0): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
                (1): ReLU()
                (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
              )),
             ('conv2',
              Sequential(
                (0): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))
                (1): ReLU()
                (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
              )),
             ('fc1',
              Sequential(
                (0): Linear(in_features=400, out_features=120, bias=True)
                (1): ReLU()
              )),
             ('fc2',
              Sequential(
                (0): Linear(in_features=120, out_features=84, bias=True)
                (1): ReLU()
              )),
             ('fc3', Linear(in_features=84, out_features=10, bias=True))])

遍历时使用.items()

model._modules.items()
odict_items([('conv1', Sequential(
  (0): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
  (1): ReLU()
  (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)), ('conv2', Sequential(
  (0): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1))
  (1): ReLU()
  (2): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)), ('fc1', Sequential(
  (0): Linear(in_features=400, out_features=120, bias=True)
  (1): ReLU()
)), ('fc2', Sequential(
  (0): Linear(in_features=120, out_features=84, bias=True)
  (1): ReLU()
)), ('fc3', Linear(in_features=84, out_features=10, bias=True))])
for name, layer in model._modules.items():
    out = layer(out)

你可能感兴趣的:(pytorch,深度学习,人工智能)