Acknowledgments
Thanks to Facebook's developer's hard work and effort -
(Google only two words to "Oh")
2 neural network to build depth
2.1 Module added
Use nn.Module.add_module()函数,
add_module()函数内部,改变的是_modules成员变量,_modules是一个OrderedDict类型的变量,
代码如下,
[docs] def add_module(self, name, module):
r"""Adds a child module to the current module.
The module can be accessed as an attribute using the given name.
Args:
name (string): name of the child module. The child module can be
accessed from this module using the given name
module (Module): child module to be added to the module.
"""
# other code
self._modules[name] = module