torch.nn.Sequential(*args)类

这是一个顺序容器,模型们将按照在构造函数中被创建的顺序添加到这个容器中。另外,也可以传递进去一个带有顺序的字典模型。

下面是一个简单的理解的例子:

  1. # Example of using Sequential
  2. model = nn.Sequential(nn.Conv2d(1, 20, 5), nn.ReLU(),
  3. nn.Conv2d(20, 64, 5), nn.ReLU())
  4. # Example of using Sequential with OrderedDict
  5. model = nn.Sequential(OrderedDict([
  6. ('conv1', nn.Conv2d(1, 20, 5)),
  7. ('relu1', nn.ReLU()),
  8. ('conv2', nn.Conv2d(20, 64, 5)),
  9. ('relu2', nn.ReLU())
  10. ]))

官网原文链接§ torch.nn.Sequential(args)类 - 图1https://pytorch.org/docs/master/generated/torch.nn.Sequential.html#sequential