Maxpool 1d shape changing

Hi,

I’ve just added a Maxpool1d into a CVAE, and the shape is changing from <x1,y1,z1> to <x2,y2> ie its changing from a 3D tensor to a 2D tensor, any ideas why this is?

Cheers,

Chaslie

Hi @chaslie
What is exactly the input shape and what are the arguments of MaxPool1d?

Hi Spanev,

the code line is

self.pool=nn.MaxPool1d(22,stride=1,padding=10,dilation=1)

The input shape is <2,128,66>
the output shape is <128,65>

the output shape is correct when i calculate, except it is now a 2D tensor and not 3D which gives:

RuntimeError: Expected 3-dimensional input for 3-dimensional weight 128 128, but got 2-dimensional input of size [128, 65] instead

Having adjustedf the maxpool line to:

self.pool=nn.MaxPool1d(22,stride=1,padding=10,dilation=1,return_indices=True)

and

def forward(self, data):
       data,indices=self.pool(data)
       return data, indices

Which is fed into a decoder using:

        self.unpool=nn.MaxUnpool1d(22,stride=1,padding=10)

and

    def forward(self, z2,indices):
         z2=self.unpool(z2,indices, output_size=input.size())

I am now getting the error:

    model(*x)

  File "d:\Users\CHARLIE\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)

TypeError: forward() missing 1 required positional argument: 'indices'

It might come from somewhere else in your model, since the input data shape and layer you give produces a [2, 128, 65] shaped output:

>>> pool=nn.MaxPool1d(22,stride=1,padding=10,dilation=1)
>>> t = torch.rand(2,128,66)
>>> pool(t).shape
torch.Size([2, 128, 65])

What is x here?

File “d:\xxxx\Anaconda3\lib\site-packages\torchsummary\torchsummary.py”, line 72, in summary
model(*x)