Having Fun with Deep Convolutional GANs

DCGAN with MNIST

Images from MNIST
Generated by a Simple GAN
Generated by DCGAN

The Difference between the Simple GAN and the DCGAN

generator = Sequential([
Dense(128, input_shape=(100,)),
LeakyReLU(alpha=0.01),
Dense(784),
Activation('tanh')
], name='generator')
generator = Sequential([
# Layer 1
Dense(784, input_shape=(100,)),
Reshape(target_shape=(7, 7, 16)),
BatchNormalization(),
LeakyReLU(alpha=0.01),
# Layer 2
Conv2DTranspose(32, kernel_size=5, strides=2, padding='same'),
BatchNormalization(),
LeakyReLU(alpha=0.01),
# Layer 3
Conv2DTranspose(1, kernel_size=5, strides=2, padding='same'),
Activation('tanh')
])
Layer (type)                 Output Shape              Param #   
=================================================================
dense_7 (Dense) (None, 784) 79184
_________________________________________________________________
reshape_5 (Reshape) (None, 7, 7, 16) 0
_________________________________________________________________
batch_normalization_7 (Batch (None, 7, 7, 16) 64
_________________________________________________________________
leaky_re_lu_5 (LeakyReLU) (None, 7, 7, 16) 0
_________________________________________________________________
conv2d_transpose_4 (Conv2DTr (None, 14, 14, 32) 12832
_________________________________________________________________
batch_normalization_8 (Batch (None, 14, 14, 32) 128
_________________________________________________________________
leaky_re_lu_6 (LeakyReLU) (None, 14, 14, 32) 0
_________________________________________________________________
conv2d_transpose_5 (Conv2DTr (None, 28, 28, 1) 801
_________________________________________________________________
activation_3 (Activation) (None, 28, 28, 1) 0
=================================================================
Total params: 93,009
Trainable params: 92,913
Non-trainable params: 96
_________________________________________________________________

DCGAN with SVHN

Images from SVHN
Generated by DCGAN
generator = Sequential([
# Layer 1
Dense(4*4*512, input_shape=(100,)),
Reshape(target_shape=(4, 4, 512)),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 2
Conv2DTranspose(256, kernel_size=5, strides=2, padding='same'),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 3
Conv2DTranspose(128, kernel_size=5, strides=2, padding='same'),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 4
Conv2DTranspose(3, kernel_size=5, strides=2, padding='same'),
Activation('tanh')
])

DCGAN with CelebA

Images from CelebA (Full Size)
Images from CelebA (Resized: 32x32)
Generated by DCGAN
from keras.initializers import RandomNormalgenerator = Sequential([
# Layer 1
Dense(4*4*512, input_shape=(100,),
kernel_initializer=RandomNormal(stddev=0.02)),
Reshape(target_shape=(4, 4, 512)),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 2
Conv2DTranspose(256, kernel_size=5, strides=2, padding='same',
kernel_initializer=RandomNormal(stddev=0.02)),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 3
Conv2DTranspose(128, kernel_size=5, strides=2, padding='same',
kernel_initializer=RandomNormal(stddev=0.02)),
BatchNormalization(),
LeakyReLU(alpha=0.2),

# Layer 4
Conv2DTranspose(3, kernel_size=5, strides=2, padding='same',
kernel_initializer=RandomNormal(stddev=0.02)),
Activation('tanh')
])

Conclusion

References

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store