Model produces random output when using loops to define hidden layers

Hi,
I think the reason is a nn.Module does not recognize any module/parameter in a Python list. You can check this by print(model)
Therefore, any parameters for those modules won’t show up when you call model.parameters(). I guess it also mess up the saving process, leading to the problem you described above.
Some solution can be found in this thread: List of nn.Module in a nn.Module