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.

filters=16,

kernel_size=3,

strides=2,

activation='relu',

instance_norm=True):

"""Builds a generic encoder layer made of Conv2D-IN-LeakyReLU

IN is optional, LeakyReLU may be replaced by ReLU

"""

conv = Conv2D(filters=filters,

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)

return x

Chapter 7

def decoder_layer(inputs,

paired_inputs,

filters=16,

kernel_size=3,

strides=2,

activation='relu',

instance_norm=True):

"""Builds a generic decoder layer made of Conv2D-IN-LeakyReLU

IN is optional, LeakyReLU may be replaced by ReLU

Arguments: (partial)

inputs (tensor): the decoder layer input

paired_inputs (tensor): the encoder layer output

provided by U-Net skip connection &

concatenated to inputs.

"""

conv = Conv2DTranspose(filters=filters,

[ 213 ]

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

Saved successfully!

Ooh no, something went wrong!