#unfreezes the discriminator layer as we are about the train it
discriminator.trainable=True
#keras requires recompialton after layers are frozen or unfrozen
discriminator.compile(loss='binary_crossentropy', optimizer=discrim_optimizer)
#trains the discrimanator
#sepearte batches to help batch norm
disc_loss_1=discriminator.train_on_batch([images,labels], valid)
disc_loss_2=discriminator.train_on_batch([gen_images,gen_labels], fake)
disc_loss_1=discriminator.train_on_batch([images,labels], valid)
disc_loss_2=discriminator.train_on_batch([gen_images,gen_labels], fake)
#takes the mean of the two discrimantor losses
disc_loss=(disc_loss_1+disc_loss_2)/2
#freezes the discrnaor layers as we want to train the geneatator layers only
discriminator.trainable=False
#keras requires recompialton after layers are frozen or unfrozen
discriminator.compile(loss='binary_crossentropy', optimizer=discrim_optimizer)
combined.compile(loss='binary_crossentropy', optimizer=gen_optimizer)
#trains the combined model (which only has generator layers trainable so we are only really training the generator) to make the discrimantor output 1 when passed generator images
gen_loss=combined.train_on_batch([noise,gen_labels], np.zeros((batch_size,1)))