class Model(nn.Module): def __init__(self): super().__init__() self.net = nn.Sequential(nn.Conv2d(3, 3, 1, 1, 0), nn.Conv2d(3, 3, 1, 1, 0)) def forward(self, x): for name, layer in self.net.named_modules(): x = layer(x)
Now the thing is
.named_modlues() will give me
first the whole thing
Sequential (so now my code has already propagated the input through the entire network)
And then the two convs.
I just want the layers to iterate over one by one.
One hardcoded solution is to skip over the first 2. which is not a good solution.
Another is to, check if the layer is present in a
list of acceptable layers and then pass the
x through it.
Any other solutions?