# Module.children() vs Module.modules()

**URL:** <https://discuss.pytorch.org/t/module-children-vs-module-modules/4551>\
**Category:** Uncategorized\
**Created:** [July 3, 2017, 8:24pm UTC](https://discuss.pytorch.org/t/module-children-vs-module-modules/4551 "2017-07-03T20:24:50Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![mnazaal](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mnazaal/32/12026_2.png) [@mnazaal](https://discuss.pytorch.org/u/mnazaal)\
**Post date:** [August 8, 2018, 9:54am UTC](https://discuss.pytorch.org/t/module-children-vs-module-modules/4551/6 "2018-08-08T09:54:40Z")

</div>

@ post above me  
You could iterate through the whole network. Think of it as a tree.

```auto
all_layers = []
def remove_sequential(network):
    for layer in network.children():
        if type(layer) == nn.Sequential: # if sequential layer, apply recursively to layers in sequential layer
            remove_sequential(layer)
        if list(layer.children()) == []: # if leaf node, add it to list
            all_layers.append(layer)

```

---

_[View the full topic](https://discuss.pytorch.org/t/module-children-vs-module-modules/4551)._
