# How is the generator code works in a GAN?

I am going throught GAN for image generation and I am using this article for reference. The author is creating a generator model which does this.

and the generator model code is

self.G = Sequential()
dropout = 0.4
depth = 64+64+64+64
dim = 7

# In: 100
# Out: dim x dim x depth

# In: dim x dim x depth
# Out: 2*dim x 2*dim x depth/2

# Out: 28 x 28 x 1 grayscale image [0.0,1.0] per pix
self.G.summary()


I understood most of the codes but I have doubts in these two functions

self.G.add(UpSampling2D())


What is happeing in those layers?

• The official documentation on UpSampling2D and Conv2DTranspose seems clear to me. What exactly is troubling you in these lines of code? Aug 1 '17 at 11:39

You should either use UpSampling2D or Conv2DTranspose.

Upsampling2D just repeats the input. After Upsampling you should add a normal convolutional layer.

Conv2DTranspose is the backpropagated Conv2D, and there you do not neet any upsampling

For both cases read the documentary. https://arxiv.org/pdf/1603.07285v1.pdf

According to the official Keras MNIST autoencoder example here:

keras/examples/mnist_denoising_autoencoder.py

You use UpSampling2D along with Conv2DTranspose when strides < 2 They claim that it is better to use Conv2DTranspose with strides >= 2

# Build the Decoder Model
latent_inputs = Input(shape=(latent_dim,), name='decoder_input')
x = Dense(shape[1] * shape[2] * shape[3])(latent_inputs)
x = Reshape((shape[1], shape[2], shape[3]))(x)

# Stack of Transposed Conv2D blocks
# Notes:
# 1) Use Batch Normalization before ReLU on deep networks
# 2) Use UpSampling2D as alternative to strides>1
# - faster but not as good as strides>1
for filters in layer_filters[::-1]:
x = Conv2DTranspose(filters=filters,
kernel_size=kernel_size,
strides=2,
activation='relu',