def grab_layers(my_list, nn): if len(list(nn.children())) > 0: for i in range(len(list(nn.children()))): my_list = grab_layers(my_list, list(nn.children())[i]) else: my_list.append(nn) return my_list
def reset(nn): def _reset(item): if hasattr(item, 'reset_parameters'): item.reset_parameters() if nn is not None: if hasattr(nn, 'children') and len(list(nn.children())) > 0: for item in nn.children(): _reset(item) else: _reset(nn)