diff --git a/BasicGAN b/BasicGAN new file mode 100644 index 0000000..07d827c --- /dev/null +++ b/BasicGAN @@ -0,0 +1,44 @@ +import tensorflow as tf +from tensorflow.keras import layers + +# Generator +def make_generator_model(): + model = tf.keras.Sequential() + model.add(layers.Dense(7*7*256, use_bias=False, input_shape=(100,))) + model.add(layers.BatchNormalization()) + model.add(layers.LeakyReLU()) + + model.add(layers.Reshape((7, 7, 256))) + assert model.output_shape == (None, 7, 7, 256) + + model.add(layers.Conv2DTranspose(128, (5, 5), strides=(1, 1), padding='same', use_bias=False)) + assert model.output_shape == (None, 7, 7, 128) + model.add(layers.BatchNormalization()) + model.add(layers.LeakyReLU()) + + model.add(layers.Conv2DTranspose(64, (5, 5), strides=(2, 2), padding='same', use_bias=False)) + assert model.output_shape == (None, 14, 14, 64) + model.add(layers.BatchNormalization()) + model.add(layers.LeakyReLU()) + + model.add(layers.Conv2DTranspose(1, (5, 5), strides=(2, 2), padding='same', use_bias=False, activation='tanh')) + assert model.output_shape == (None, 28, 28, 1) + + return model + +# Discriminator +def make_discriminator_model(): + model = tf.keras.Sequential() + model.add(layers.Conv2D(64, (5, 5), strides=(2, 2), padding='same', + input_shape=[28, 28, 1])) + model.add(layers.LeakyReLU()) + model.add(layers.Dropout(0.3)) + + model.add(layers.Conv2D(128, (5, 5), strides=(2, 2), padding='same')) + model.add(layers.LeakyReLU()) + model.add(layers.Dropout(0.3)) + + model.add(layers.Flatten()) + model.add(layers.Dense(1)) + + return model