torch.nn.Sequential(*args)类
这是一个顺序容器,模型们将按照在构造函数中被创建的顺序添加到这个容器中。另外,也可以传递进去一个带有顺序的字典模型。
下面是一个简单的理解的例子:
# 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())
]))
官网原文链接 :https://pytorch.org/docs/master/generated/torch.nn.Sequential.html#sequential