16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Cross-Domain GANs

kernel_size=kernel_size,

strides=strides,

padding='same')

x = inputs

if instance_norm:

x = InstanceNormalization()(x)

if activation == 'relu':

x = Activation('relu')(x)

else:

x = LeakyReLU(alpha=0.2)(x)

x = conv(x)

x = concatenate([x, paired_inputs])

return x

Listing 7.1.2, cyclegan-7.1.1.py. Generator implementation in Keras:

def build_generator(input_shape,

output_shape=None,

kernel_size=3,

name=None):

"""The generator is a U-Network made of a 4-layer encoder

and a 4-layer decoder. Layer n-i is connected to layer i.

Arguments:

input_shape (tuple): input shape

output_shape (tuple): output shape

kernel_size (int): kernel size of encoder & decoder layers

name (string): name assigned to generator model

Returns:

generator (Model):

"""

inputs = Input(shape=input_shape)

channels = int(output_shape[-1])

e1 = encoder_layer(inputs,

32,

kernel_size=kernel_size,

activation='leaky_relu',

strides=1)

e2 = encoder_layer(e1,

64,

activation='leaky_relu',

[ 214 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!