The following model returns the error: TypeError: forward() missing 1 required positional argument: 'indices'
I've exhausted many online examples and they all look similar to my code. My maxpool layer returns both the input and the indices for the unpool layer. Any ideas on what's wrong?
class autoencoder(nn.Module):
def __init__(self):
super(autoencoder, self).__init__()
self.encoder = nn.Sequential(
...
nn.MaxPool2d(2, stride=1, return_indices=True)
)
self.decoder = nn.Sequential(
nn.MaxUnpool2d(2, stride=1),
...
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
Similar to the question here, the solution seems to be to separate the maxunpool layer from the decoder and explicitly pass its required parameters. nn.Sequential only takes one parameter.
class SimpleConvAE(nn.Module):
def __init__(self):
super().__init__()
# input: batch x 3 x 32 x 32 -> output: batch x 16 x 16 x 16
self.encoder = nn.Sequential(
...
nn.MaxPool2d(2, stride=2, return_indices=True),
)
self.unpool = nn.MaxUnpool2d(2, stride=2, padding=0)
self.decoder = nn.Sequential(
...
)
def forward(self, x):
encoded, indices = self.encoder(x)
out = self.unpool(encoded, indices)
out = self.decoder(out)
return (out, encoded)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With