CLASS torch.nn.Sequential(*args: Any)
顺序容器。模块将按照在构造函数中传递的顺序添加到它。或者,也可以传入模块的有序字典。
为了便于理解,这里有一个小例子:
# 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())
]))