Prajwal Satpute
Prajwal Satpute

Reputation: 1

RuntimeError: mat1 and mat2 shapes cannot be multiplied (128x256 and 32768x1)

class Discriminator(nn.Module):
    def __init__(self, img_shape):
        super(Discriminator, self).__init__()        
        self.Conv1 = nn.Conv2d(3, 16, 4, stride=2, padding=1)
        self.leaky1 = nn.LeakyReLU(0.2, inplace=True)
        self.Conv2 = nn.Conv2d(16, 32, 4, stride=2, padding=1)
        self.leaky2 = nn.LeakyReLU(0.2, inplace=True)      
        self.Conv3 = nn.Conv2d(32, 64, 4, stride=2, padding=1)
        self.leaky3 = nn.LeakyReLU(0.2, inplace=True)      
        self.Conv4 = nn.Conv2d(64, 128, 4, stride=2, padding=1)
        self.leaky4 = nn.LeakyReLU(0.2, inplace=True)      
        self.fc_size = 128 * 16 * 16
        self.linear1 = nn.Linear(self.fc_size, 1)
        self.sigmoid1 = nn.Sigmoid()
        
    def forward(self, img):

        x = self.leaky1(self.Conv1(img))
        x = self.leaky2(self.Conv2(x))
        x = self.leaky3(self.Conv3(x))
        x = self.leaky4(self.Conv4(x))
        x = x.view(x.size(0), -1)
        x = self.linear1(x)
        output = self.sigmoid1(x)
        return output

This is how my discriminator looks like and I tried training it but gave this error. I don't understand why flattening is going wrong in this.

I couldn't trace the problem, I ahve tried almost everything but I may have been missing something.

Upvotes: 0

Views: 14

Answers (0)

Related Questions