Arbitrary shaped Feedforward Neural Network in Pytorch
I am making a script that has some generative aspect to it, and I need to generate arbitrary shaped  feedforward NNs. The idea is to pass a list With the number of number of neurons in each layer, and the number of layers is determined by the length of the list:
shape = [784,64,64,64,10]

I tried something like this:
shapenn = [784,64,64,64,10]
class Net(nn.Module):
    def __init__(self, shapenn):
        super().__init__()
        self.shapenn = shapenn
        self.fcl = [] # list with fully conected leyers 
        for i in range(len(act_funs)):
            self.fcl.append(nn.Linear(self.nnarch[i],self.nnarch[i+1]))
net = Net(shapenn)

While the fully connected layers are created correctly in the list fcl, net is not initialized properly for example it has not net.parameters().
I am sure there is a correct way to do this, thank you very much in advance.

You need to use nn.ModuleList in place of the built-in python list (similarly use nn.ModuleDict in place of python dictionaries). These behave like a normal list except that they must only contain instances that subclasses nn.Module and using them signals that the modules contained in the list should be considered submodules of your module. For example
import torch.nn as nn

class Net(nn.Module):
    def __init__(self):
        super().__init__()
        self.fcl = nn.ModuleList()
        for i in range(5):
            self.fcl.append(nn.Linear(10, 10))

net = Net()
print([name for name, val in net.named_parameters()])

prints
['fcl.0.weight', 'fcl.0.bias', 'fcl.1.weight', 'fcl.1.bias', 'fcl.2.weight', 'fcl.2.bias', 'fcl.3.weight', 'fcl.3.bias', 'fcl.4.weight', 'fcl.4.bias']

