How to create MLP model with arbitrary number of hidden layers

You should use a nn.ModuleList instead of a python list. Looking at this topic might be useful: When should I use nn.ModuleList and when should I use nn.Sequential?

3 Likes