Building The Discriminator
Learn to build the discriminator class and define the network architecture and functions forward() and train().
We'll cover the following...
The Discriminator
class
Let’s code the discriminator. Just like before, it is a neural network with a class inherited from nn.Module
. We follow the expected PyTorch patterns for initializing the network and providing a forward()
function.
Have a look at the following constructor for a Discriminator
class.
Press + to interact
class Discriminator(nn.Module):def __init__(self):# initialise parent pytorch classsuper().__init__()# define neural network layersself.model = nn.Sequential(nn.Linear(4, 3),nn.Sigmoid(),nn.Linear(3, 1),nn.Sigmoid())# create loss functionself.loss_function = nn.MSELoss()# create optimiser, using stochastic gradient descentself.optimiser = torch.optim.SGD(self.parameters(), lr=0.01)# counter and accumulator for progressself.counter = 0self.progress = []pass
...