...

/

Building The Discriminator

Building The Discriminator

Learn to build the discriminator class and define the network architecture and functions forward() and train().

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 class
super().__init__()
# define neural network layers
self.model = nn.Sequential(
nn.Linear(4, 3),
nn.Sigmoid(),
nn.Linear(3, 1),
nn.Sigmoid()
)
# create loss function
self.loss_function = nn.MSELoss()
# create optimiser, using stochastic gradient descent
self.optimiser = torch.optim.SGD(self.parameters(), lr=0.01)
# counter and accumulator for progress
self.counter = 0
self.progress = []
pass
...