Creating models

Create the Keras models as we did previously, which are specified in the Stage-I StackGAN section under A Keras implementation of StackGAN:

Start by defining the optimizers required for the training:

dis_optimizer = Adam(lr=stage1_discriminator_lr, beta_1=0.5, beta_2=0.999)
gen_optimizer = Adam(lr=stage1_generator_lr, beta_1=0.5, beta_2=0.999)

We will use the Adam optimizer with the learning rate equal to 0.0002 and the beta_1 value equal to 0.5 and beta_2 equal to 0.999.

Now build and create models:

stage2_dis = build_stage2_discriminator()
stage2_dis.compile(loss='binary_crossentropy', optimizer=dis_optimizer)

stage1_gen = build_stage1_generator()
stage1_gen.compile(loss="binary_crossentropy", optimizer=gen_optimizer)

stage1_gen.load_weights("stage1_gen.h5")

stage2_gen = build_stage2_generator()
stage2_gen.compile(loss="binary_crossentropy", optimizer=gen_optimizer)

embedding_compressor_model = build_embedding_compressor_model()
embedding_compressor_model.compile(loss='binary_crossentropy', optimizer='adam')

adversarial_model = build_adversarial_model(stage2_gen, stage2_dis, stage1_gen)
adversarial_model.compile(loss=['binary_crossentropy', KL_loss], loss_weights=[1.0, 2.0],
optimizer=gen_optimizer, metrics=None)

KL_loss is the custom loss function, which is specified in the Training the Stage-I StackGAN section.

We now have the dataset and models ready for the Stage-II StackGAN. Let's train the model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178