-
-
Save RaphaelMeudec/d1a37d2543c3b223cf16643b5bd06cc2 to your computer and use it in GitHub Desktop.
This file contains 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
from keras.layers import Input | |
from keras.layers.advanced_activations import LeakyReLU | |
from keras.layers.convolutional import Conv2D | |
from keras.layers.core import Dense, Flatten | |
from keras.layers.normalization import BatchNormalization | |
from keras.models import Model | |
ndf = 64 | |
output_nc = 3 | |
input_shape_discriminator = (256, 256, output_nc) | |
def discriminator_model(): | |
"""Build discriminator architecture.""" | |
n_layers, use_sigmoid = 3, False | |
inputs = Input(shape=input_shape_discriminator) | |
x = Conv2D(filters=ndf, kernel_size=(4,4), strides=2, padding='same')(inputs) | |
x = LeakyReLU(0.2)(x) | |
nf_mult, nf_mult_prev = 1, 1 | |
for n in range(n_layers): | |
nf_mult_prev, nf_mult = nf_mult, min(2**n, 8) | |
x = Conv2D(filters=ndf*nf_mult, kernel_size=(4,4), strides=2, padding='same')(x) | |
x = BatchNormalization()(x) | |
x = LeakyReLU(0.2)(x) | |
nf_mult_prev, nf_mult = nf_mult, min(2**n_layers, 8) | |
x = Conv2D(filters=ndf*nf_mult, kernel_size=(4,4), strides=1, padding='same')(x) | |
x = BatchNormalization()(x) | |
x = LeakyReLU(0.2)(x) | |
x = Conv2D(filters=1, kernel_size=(4,4), strides=1, padding='same')(x) | |
if use_sigmoid: | |
x = Activation('sigmoid')(x) | |
x = Flatten()(x) | |
x = Dense(1024, activation='tanh')(x) | |
x = Dense(1, activation='sigmoid')(x) | |
model = Model(inputs=inputs, outputs=x, name='Discriminator') | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment