'tuple' object is not callable in Model.forward

class Model(nn.Module):
def init (self):
super(Model, self).init()
self.conv1 = nn.Sequential(
nn.Conv2d(1, 32, kernel_size = (3,3), stride = (1,1),padding = (0,1)),
nn.BatchNorm2d(num_features =32),
nn.ReLU(inplace = True),
nn.AvgPool2d(kernel_size = (2,2), stride =(2,2)),
)

    self.conv2 = nn.Sequential(
        nn.Conv2d(32, 64, kernel_size = (3,3), stride = (1,1), padding = (1,1)),
        nn.BatchNorm2d(num_features =64),
        nn.ReLU(inplace = True),
        nn.Dropout(p=0.10),
        nn.AvgPool2d(kernel_size = (2,2), stride =(2,2)),
    )    
        
    self.conv3 = nn.Sequential(
        nn.Conv2d(64, 64, kernel_size = (3,3), stride = (1,2)),
        nn.BatchNorm2d(num_features =64),
        nn.ReLU(inplace = True),
        nn.AvgPool2d(kernel_size = (3,3), stride =(1,1)),
    )
    
    self.Linear1 = nn.Linear(1*64*122,4),
    
def forward(self, x):
    out = self.conv1(x)
    out = self.conv2(out)
    out = self.conv3(out)
    N, C, H, W = out.size()     
    out = out.view(N, -1)
    output = self.Linear1(out)
    return output

model = Model()

When I run the code, it told me that

β€˜β€™β€™β€™
output = self.Linear1(out)

TypeError: β€˜tuple’ object is not callable
β€˜β€™β€™β€™β€™

5 Likes

It’s a syntax problem. You have a comma after

The interpreter thinks that this is a tuple. Just delete it and you should be good to go.

:smile_cat:

14 Likes

Yeeeaaahhhhhhhhh! It works! Thank you very much!

2 Likes

I did the same mistake :sweat_smile: and thank you for your answer

hero! of! the! day!!

1 Like