pytorch中的Sequential使用方法

原文链接: https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-nn/#class-torchnnsequential-args

class torch.nn.Sequential(* args)

一个时序容器。Modules 会以他们传入的顺序被添加到容器中。当然,也可以传入一个OrderedDict

为了更容易的理解如何使用Sequential, 下面给出了一个例子:

# Example of using Sequential

model = nn.Sequential(
          nn.Conv2d(1,20,5),
          nn.ReLU(),
          nn.Conv2d(20,64,5),
          nn.ReLU()
        )
# Example of using Sequential with OrderedDict
model = nn.Sequential(OrderedDict([
          ('conv1', nn.Conv2d(1,20,5)),
          ('relu1', nn.ReLU()),
          ('conv2', nn.Conv2d(20,64,5)),
          ('relu2', nn.ReLU())
        ]))

你可能感兴趣的:(python,study,pytorch)