Skip to content

Instantly share code, notes, and snippets.

@jamescalam
Last active May 14, 2020 13:05
Show Gist options
  • Select an option

  • Save jamescalam/1d4897bfa61bc7fc2fef76ef845c2f66 to your computer and use it in GitHub Desktop.

Select an option

Save jamescalam/1d4897bfa61bc7fc2fef76ef845c2f66 to your computer and use it in GitHub Desktop.
Methods used in the generator class for a DCGAN.
# this should be placed outside the class, as it will be used by the discriminator too
cross_entropy = tf.keras.losses.BinaryCrossentropy(from_logits=True)
# the following are contained within the Generator class
def optimiser(self, learning_rate):
self.opt = tf.optimizers.Adam(learning_rate)
def loss(self, fake_preds):
# calculate the loss with binary cross-entropy
fake_loss = cross_entropy(tf.ones_like(fake_preds), fake_preds)
# return the fake predictions loss
return fake_loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment