Created
September 16, 2021 11:21
-
-
Save rohan-paul/fff3ae0a502f873bf95613298078b41c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| noise_shape = 100 | |
| # Generator will upsample our seed using convolutional transpose layers (upsampling layers) | |
| def generator_model(): | |
| generator=Sequential() | |
| # Random noise to 4x4x512 image | |
| generator.add(Dense(4*4*512, input_shape=[noise_shape])) | |
| # Next, add a reshape layer to the network to reshape the tensor from the | |
| # last layer to a tensor of a shape of (4, 4, 512): | |
| generator.add(Reshape([4,4,512])) | |
| generator.add(Conv2DTranspose(256, kernel_size=4, strides=2, padding="same")) | |
| # BatchNormalization is added to the model after the hidden layer, but before the activation, such as LeakyReLU. | |
| generator.add(BatchNormalization()) | |
| generator.add(LeakyReLU(alpha=0.2)) | |
| generator.add(Conv2DTranspose(128, kernel_size=4, strides=2, padding="same")) | |
| generator.add(LeakyReLU(alpha=0.2)) | |
| generator.add(BatchNormalization()) | |
| generator.add(Conv2DTranspose(64, kernel_size=4, strides=2, padding="same")) | |
| generator.add(LeakyReLU(alpha=0.2)) | |
| generator.add(BatchNormalization()) | |
| generator.add(Conv2DTranspose(3, kernel_size=4, strides=2, padding="same", | |
| activation='sigmoid')) | |
| return generator | |
| generator = generator_model() | |
| generator.summary() | |
| def discriminator_model(): | |
| discriminator = Sequential() | |
| discriminator.add(Conv2D(64, (3,3), strides=(2, 2), padding='same', input_shape=[64,64, 3])) | |
| discriminator.add(LeakyReLU(alpha=0.2)) | |
| discriminator.add(Dropout(0.4)) | |
| discriminator.add(Conv2D(64, (3,3), strides=(2, 2), padding='same')) | |
| discriminator.add(BatchNormalization()) | |
| discriminator.add(LeakyReLU(alpha=0.2)) | |
| discriminator.add(Dropout(0.4)) | |
| discriminator.add(Flatten()) | |
| discriminator.add(Dense(1, activation='sigmoid')) | |
| return discriminator | |
| discriminator = discriminator_model() | |
| discriminator.summary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment