MaxUnpool2d with indices from MaxPool2d, all in nn.Sequential

Hey all, I saw it recommended to reserve Sequential for only the most trivial networks, but I’m a big fan of the readability/simplicity and I’m trying to keep as much of my network in nn.Sequential as possible.

Is there a simple way to use MaxUnpool2d layers in one Sequential block with respect to the indices from MaxPool2d layers in a previous block?

1 Like

there isn’t at the moment

Thanks. Are there plans to add more of that kind of support for working in Sequential?

no, we dont plan to make Sequential work on complex networks, it was provided as a one-off convenience container for really simple networks

Fair enough, thanks.

def forward(self, x):
        for layers in self.front_process:
            if isinstance(layers, nn.MaxPool2d):
                print('\ngot target1\n')
        print('\n\nmiddle \n\n')
        for layers in self.back_process:
            if isinstance(layers, nn.MaxUnpool2d):
                print('\ngot target2\n')

You can try this to extract maxpool and maxunpool, but I don’t know whether it will influence the speed or not, since I’m quite new to pytorch.