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,

name=dt_name)

d_source = build_discriminator(source_shape,

patchgan=patchgan,

kernel_size=kernel_size,

name=ds_name)

print('---- TARGET DISCRIMINATOR ----')

d_target.summary()

print('---- SOURCE DISCRIMINATOR ----')

d_source.summary()

optimizer = RMSprop(lr=lr, decay=decay)

d_target.compile(loss='mse',

optimizer=optimizer,

metrics=['accuracy'])

d_source.compile(loss='mse',

optimizer=optimizer,

metrics=['accuracy'])

# freeze the discriminator weights in the adversarial model

d_target.trainable = False

d_source.trainable = False

# build the computational graph for the adversarial model

# forward cycle network and target discriminator

source_input = Input(shape=source_shape)

fake_target = g_target(source_input)

preal_target = d_target(fake_target)

reco_source = g_source(fake_target)

# backward cycle network and source discriminator

target_input = Input(shape=target_shape)

fake_source = g_source(target_input)

preal_source = d_source(fake_source)

reco_target = g_target(fake_source)

# if we use identity loss, add 2 extra loss terms

# and outputs

if identity:

iden_source = g_source(source_input)

iden_target = g_target(target_input)

loss = ['mse', 'mse', 'mae', 'mae', 'mae', 'mae']

loss_weights = [1., 1., 10., 10., 0.5, 0.5]

inputs = [source_input, target_input]

outputs = [preal_source,

[ 220 ]

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

Saved successfully!

Ooh no, something went wrong!