'tuple' object is not callable error for DCGAN

Hello everyone !

I am trying to code a DCGAN from scratch but I have some issues and I hope you can help me with it.

I defined my Generator as following :

class Generator(nn.Module):
    """docstring for Generator."""
    def __init__(self):
        super(Generator, self).__init__()
        self.Tconv1 = nn.ConvTranspose2d(in_channels = 1, out_channels = 1024, kernel_size = 4), #(batch, 4, 4, 1024)
        self.batch1 = nn.BatchNorm2d(1024),
        self.Tconv2 = nn.ConvTranspose2d(1024, 512, 5), #(B, 8, 8, 512)
        self.batch2 = nn.BatchNorm2d(512),
        self.Tconv3 = nn.ConvTranspose2d(512, 256, kernel_size=4, stride=2, padding=1), #(B, 16, 16, 256)
        self.batch3 = nn.BatchNorm2d(256),
        self.Tconv4 = nn.ConvTranspose2d(256, 128, kernel_size=4, stride=2, padding=1), #(B, 32, 32, 256)
        self.batch4 = nn.BatchNorm2d(256),
        self.Tconv5 = nn.ConvTranspose2d(128, 3, kernel_size=4, stride=2, padding=1), #(B, 32, 32, 256)
        
        
    def forward(self, z):
        z_conv = F.relu(self.batch1(self.Tconv1(z)))
        z_conv = F.relu(self.batch2(self.Tconv2(z_conv)))
        z_conv = F.relu(self.batch3(self.Tconv3(z_conv)))
        z_conv = F.relu(self.batch4(self.Tconv4(z_conv)))
        z_conv = F.tanh(self.Tconv5(z_conv))
        return z_conv

with this input :

z = torch.randn(100).view(-1, 100, 1, 1) 
z = Variable(z, volatile=True)
generator_test = Generator()
generator_test.forward(z)

However I get a Type Error : ‘tuple’ object is not callable in

 F.relu(self.batch1(self.Tconv1(z)))

I don’t understand where is the problem, so if you have any feedback on it, I would appreciate to read it.

Thanks a lot.

You have an unnecessary comma after the definition of self.Tconv1, which makes it a tuple with one entry.
Remove it and also change the in_channels to 100 to match z's channels. :wink:

1 Like