which means that it does not go inside the second Sequential, and thus does not print individually Sigmoid. On the other hand, m.modules() recursively walks into all modules in the network, and yields
@ post above me
You could iterate through the whole network. Think of it as a tree.
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)
In this operation, the names of all the nodes are different from the original name. For example, the original name of a convolution layer may be ‘conv_3_3’. However, the name becomes some numeric number, e.g., ‘10’, under this operation. Is there way to remain each layer’s original name after this kind of operation?
I bumped to that issue while trying to find memory leakage in a custom architecture. To get the number of the children that are not parents to any other module, thus the real number of modules inside the provided one, I am using this recursive function:
def dim(module):
total_num = 0
f = False
for child in module.children():
f = True
total_num += dim(child)
if not f:
return 1
return total_num