Returns an iterator over all modules in the network.(返回网络中所有模块的迭代器。)
Yields
Module – a module in the network
>>> l = nn.Linear(2, 2)
>>> net = nn.Sequential(l, l)
>>> for idx, m in enumerate(net.modules()):
print(idx, '->', m)
0 -> Sequential(
(0): Linear(in_features=2, out_features=2, bias=True)
(1): Linear(in_features=2, out_features=2, bias=True)
)
1 -> Linear(in_features=2, out_features=2, bias=True)
Submodules assigned in this way will be registered, and will have their parameters converted too when you call to()
, etc