2
$\begingroup$

Why are the generator and discriminator designed differently in the example My First GAN of the coursera course: Build Basic Generative Adversarial Networks (GANs)?

Why didn't we use the same set of layers and activation functions for both generator and discriminator?

On what basis are the layer parameters and the activation functions decided in the generator and the discriminator?

The generator layer is as follows

> def get_generator_block(input_dim, output_dim):
>     '''
>     Function for returning a block of the generator's neural network
>     given input and output dimensions.
>     Parameters:
>         input_dim: the dimension of the input vector, a scalar
>         output_dim: the dimension of the output vector, a scalar
>     Returns:
>         a generator neural network layer, with a linear transformation 
>           followed by a batch normalization and then a relu activation
>     '''
>     return nn.Sequential(
>         nn.Linear(input_dim, output_dim),
>         nn.BatchNorm1d(output_dim),
>         nn.ReLU(inplace=True)         
>     )

The discriminator layer is as follows

def get_discriminator_block(input_dim, output_dim):
    '''
    Discriminator Block
    Function for returning a neural network of the discriminator given input and output dimensions.
    Parameters:
        input_dim: the dimension of the input vector, a scalar
        output_dim: the dimension of the output vector, a scalar
    Returns:
        a discriminator neural network layer, with a linear transformation 
          followed by an nn.LeakyReLU activation with negative slope of 0.2 
    return nn.Sequential(
        nn.Linear(input_dim,output_dim),
        nn.LeakyReLU(negative_slope = 0.2, inplace = True)
    )
$\endgroup$

1 Answer 1

6
$\begingroup$

In general both the generator and discriminator of GANs would consist of multiple convolutional or linear layers to capture complex patterns in the data. And the specific code you provided seems to define basic building blocks for the generator and discriminator given input/output dimensions. The choice of the number of possible hidden layers and activation functions depends on factors such as the complexity of the data, the desired level of model capacity, and the trade-off between model performance and computational efficiency.

Regarding your question about the principle of different design choices for generator and discriminator, you need to start from their different functions. The generator typically starts with a low-dimensional noise vector and gradually transforms it into a high-dimensional output that should resemble real data. The architecture often involves deconvolutions (transposed convolutions) to upsample the data. Batch normalization (or better layer/instance normalization) and ReLU activations are commonly used to try to stablize and speedup training and introduce non-linearity. The final layer might use a different activation function such as tanh to match the desired or required output range.

The discriminator, on the other hand, takes an input (real or generated) and outputs a probability indicating whether the input is real or generated. It doesn't need to upsample or generate data thus it's comparatively much simpler to focus on classifying the input without any normalization optimization scheme requirement. Leaky ReLU activations are commonly used in the discriminator to introduce a small negative slope, helping prevent the vanishing gradient problem during training. The final layer might use a sigmoid activation to produce a probability score.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .