class torch.nn.Sequential
(*args)[source]
顺序容器。模块将按照在构造函数中传递的顺序添加到它。或者,也可以传入模块的有序字典。例:
代码语言:javascript复制# 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())
]))
print(model)
print(type(model))
Output:
---------------------------------------------------------------
Sequential(
(conv1): Conv2d(1, 20, kernel_size=(5, 5), stride=(1, 1))
(relu1): ReLU()
(conv2): Conv2d(20, 64, kernel_size=(5, 5), stride=(1, 1))
(relu2): ReLU()
)
<class 'torch.nn.modules.container.Sequential'>
---------------------------------------------------------------