upsampling in the progressive gan network

Viewed 59

enter image description here

I am reading the paper about progressive gan. I am a bit confused about how the convolution work in this network. For example, does conv 4*4 mean a normal convolution? If so why a 512*1*1 shape will become 512*4*4 after conv 4*4? Is it actually a transposed convolution?

1 Answers

Why a 512*1*1 shape will become 512*4*4?

Because in GAN networks, We use Upsampling or Con2DTranspose. I Write a very small block of this network with Upsampling and Con2DTranspose.

Upsampling:

import tensorflow as tf

def upsampling(latent_size):
    inp = tf.keras.layers.Input(shape=(latent_size,))
    x = tf.keras.layers.Dense(512 * 1 * 1)(inp)
    x = tf.keras.layers.Reshape((1, 1, 512))(x)

    x = tf.keras.layers.UpSampling2D((4,4))(x)
    x = tf.keras.layers.Conv2D(512, (2,2), padding='same')(x)
    out = tf.keras.layers.LeakyReLU(alpha=0.2)(x)

    model = tf.keras.models.Model(inp, out)
    return model


tmp_model = upsampling(latent_size=100)
tmp_model.summary()

Output:

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_2 (InputLayer)        [(None, 100)]             0         
                                                                 
 dense_1 (Dense)             (None, 512)               51712     
                                                                 
 reshape_1 (Reshape)         (None, 1, 1, 512)         0         
                                                                 
 up_sampling2d_1 (UpSampling  (None, 4, 4, 512)        0         
 2D)                                                             
                                                                 
 conv2d_1 (Conv2D)           (None, 4, 4, 512)         1049088   
                                                                 
 leaky_re_lu_1 (LeakyReLU)   (None, 4, 4, 512)         0         
                                                                 
=================================================================
Total params: 1,100,800
Trainable params: 1,100,800
Non-trainable params: 0
_________________________________________________________________

Con2DTranspose:

import tensorflow as tf

def conv2dtranspose(latent_size):
    inp = tf.keras.layers.Input(shape=(latent_size,))
    x = tf.keras.layers.Dense(512 * 1 * 1)(inp)
    x = tf.keras.layers.Reshape((1, 1, 512))(x)

    x = tf.keras.layers.Conv2DTranspose(512, (2,2), strides=(4,4), padding='same')(x)
    out = tf.keras.layers.LeakyReLU(alpha=0.2)(x)

    model = tf.keras.models.Model(inp, out)
    return model


tmp_model = conv2dtranspose(latent_size=100)
tmp_model.summary()

Output:

Model: "model"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 input_4 (InputLayer)        [(None, 100)]             0         
                                                                 
 dense_3 (Dense)             (None, 512)               51712     
                                                                 
 reshape_3 (Reshape)         (None, 1, 1, 512)         0         
                                                                 
 conv2d_transpose_1 (Conv2DT  (None, 4, 4, 512)        1049088   
 ranspose)                                                       
                                                                 
 leaky_re_lu_3 (LeakyReLU)   (None, 4, 4, 512)         0         
                                                                 
=================================================================
Total params: 1,100,800
Trainable params: 1,100,800
Non-trainable params: 0
_________________________________________________________________
Related