I think simply printing the model should work here:
net = MyModel()
print(net)
if you are using a notebook - you don’t even need the print command
here is what you get:
MyModel(
(cl1): Linear(in_features=25, out_features=60, bias=True)
(cl2): Linear(in_features=60, out_features=84, bias=True)
(fc1): Linear(in_features=84, out_features=10, bias=True)
(params_list_a): ParameterList(
(0): Parameter containing: [torch.FloatTensor of size 60x25]
(1): Parameter containing: [torch.FloatTensor of size 84x60]
(2): Parameter containing: [torch.FloatTensor of size 84x10]
)
(params_list_b): ParameterList(
(0): Parameter containing: [torch.FloatTensor of size 60x25]
(1): Parameter containing: [torch.FloatTensor of size 60]
(2): Parameter containing: [torch.FloatTensor of size 84x60]
(3): Parameter containing: [torch.FloatTensor of size 84]
(4): Parameter containing: [torch.FloatTensor of size 10x84]
(5): Parameter containing: [torch.FloatTensor of size 10]
)
)
print(net.cl2)
Linear(in_features=60, out_features=84, bias=True)
but this assumes you know the layer names and does not provide for iteration
for name, module in net.named_children():
if not name.startswith(‘params’):
print(name)
print(module)
print(’------’)

cl1
Linear(in_features=25, out_features=60, bias=True)

cl2
Linear(in_features=60, out_features=84, bias=True)

fc1
Linear(in_features=84, out_features=10, bias=True)
so now you can create a list:
layers_list=[]
for name, module in net.named_children():
if not name.startswith(‘params’):
layers_list.append(name)
layers_list = [‘cl1’, ‘cl2’, ‘fc1’]