Skip to content

nn.Module not importing parameters contained in lists #666

@psmaragdis

Description

@psmaragdis

I'm not sure if this is the intended behavior or not. nn.Module does not look for parameters inside lists. This makes it hard to e.g. initialize a network, provide the number of layers as an argument, and then store these layers in a list.

For example:

class net( nn.Module):
    def __init__( self, num_layers):
        super( net, self).__init__()

        self.layer = nn.Linear( 1, 1)
        self.list_of_layers = [nn.Linear( 1, 1) for i in range( num_layers)]

n = net( 4)
print n

Returns:

net (
  (layer): Linear (1 -> 1)
)

I would have expected the parameters in self.list_of_layers to be have been inherited as the network parameters too.

Is there another recommended way that allows storage of an arbitrary number layers?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions