# Why does a cGAN's discriminator use a linear transformation?

Hi Everyone,

I have been trying to dive deeper into cGANs using pytorch and I see across implementations that the discriminator applies a linear transformation to the input data and was wondering why ?
The cGAN paper mentions that D or G can be a linear or non-linear mapping function. So I am assuming `self.linear` ensure that D is a linear mapping function, but on to exactly ?

``````# Discriminator Model
class Discriminator(nn.Module):
def __init__(self, ngpu=1):
super(Discriminator, self).__init__()
self.label_emb = nn.Embedding(n_class, ndf*16*4)
self.ngpu = ngpu
self.main = nn.Sequential(
# input is (nc) x 64 x 64
nn.Conv2d(nc, ndf, 4, 2, 1, bias=False),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf) x 32 x 32
nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 2),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*2) x 16 x 16
nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 4),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*4) x 8 x 8
nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 8),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*8) x 4 x 4
nn.Conv2d(ndf * 8, ndf * 16, 4, 2, 1, bias=False),
nn.BatchNorm2d(ndf * 16),
nn.LeakyReLU(0.2, inplace=True),
# state size. (ndf*16) x 2 x 2
nn.Flatten()
)
self.linear = nn.Sequential(
nn.Linear(ndf*16*4*2, ndf*16),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(ndf*16, 1),
nn.Sigmoid()
)

def forward(self, input, labels):
disc_out = self.main(input)
linear_input = torch.cat((self.label_emb(labels), disc_out), 1)
linear_output = self.linear(linear_input.squeeze())
return linear_output.unsqueeze(2).unsqueeze(3)
``````