TypeError: max_pool2d(): argument 'input' (position 1) must be Tensor, not tuple

I keep getting this error, but I’m not sure why. I’ve checked the shape of my input and its a tensor of shape [1, 256, 20, 24]. SO I dont know why it gives this error. Below is the code. Thanks

class MLP_model_lvl1(torch.nn.Module):
        def __init__(self, pretrained_model_lvl1):
            super(MLP_model_lvl1, self).__init__()
            self.pretrained_model_lvl1 = pretrained_model_lvl1
            self.hidden = 64
            output_dims = 1
            self.relu = torch.nn.ReLU()
            self.fc2 = torch.nn.Linear(self.hidden, self.hidden)
            self.fc3 = torch.nn.Linear(self.hidden, output_dims)
            self.max_pool = nn.MaxPool2d(kernel_size = 3, stride= 2, padding = 1)
            
        
        def forward(self, x, y, reg_code, pretrained):
            e0 = self.pretrained_model_lvl1(x, y, reg_code, pretrained) #shape [1, 256, 20, 24]
            # print(e0.shape, e0)
            e0 = self.max_pool(e0) #the error is here
            encoded = e0.flatten(1, -1)
            return encoded


The layer itself works fine with a single tensor input:

max_pool = nn.MaxPool2d(kernel_size = 3, stride= 2, padding = 1)
x = torch.randn(1, 256, 20, 24)            
out = max_pool(x)
print(out.shape)
# torch.Size([1, 256, 10, 12])

and the error claims that e0 is a tuple so make sure it’s a tensor instead.

This is the shape I get(which is a tensor), I’m not sure why it gives that error.
image

And the type is a tensor (image is attached below)
image

That’s weird as it should work in this case as you can see in my code.
Could you post a minimal and executable code snippet reproducing your error, please?

It stopped giving me an error after I ran it multiple times. (Not sure what the problem was or how it got fixed.