From dc7ad67cfbde855eadfa912578ada9743fff87ae Mon Sep 17 00:00:00 2001 From: Mirko <mirko.birbaumer@hslu.ch> Date: Thu, 7 Apr 2022 07:54:02 +0000 Subject: [PATCH] Added comments to GAN's --- ..., GAN's, DeepDream, and Neural Style Transfer.ipynb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/notebooks/Block_7/Jupyter Notebook Block 7 - Generative Models - VAE, GAN's, DeepDream, and Neural Style Transfer.ipynb b/notebooks/Block_7/Jupyter Notebook Block 7 - Generative Models - VAE, GAN's, DeepDream, and Neural Style Transfer.ipynb index 7a1ba1e..e805bea 100644 --- a/notebooks/Block_7/Jupyter Notebook Block 7 - Generative Models - VAE, GAN's, DeepDream, and Neural Style Transfer.ipynb +++ b/notebooks/Block_7/Jupyter Notebook Block 7 - Generative Models - VAE, GAN's, DeepDream, and Neural Style Transfer.ipynb @@ -1305,16 +1305,21 @@ " \n", " \n", " def train_step(self, real_images):\n", + " # Samples random points in the latent space\n", " batch_size = tf.shape(real_images)[0]\n", " random_latent_vectors = tf.random.normal(\n", " shape=(batch_size, self.latent_dim))\n", + " # Decodes them to fake images\n", " generated_images = self.generator(random_latent_vectors)\n", + " # Combines them with real images\n", " combined_images = tf.concat([generated_images, real_images], axis=0)\n", + " # Assembles labels, discriminating real from fake images\n", " labels = tf.concat(\n", " [tf.ones((batch_size, 1)), tf.zeros((batch_size, 1))], axis=0\n", " )\n", + " # Adds random noise to the labels — an important trick!\n", " labels += 0.05 * tf.random.uniform(tf.shape(labels))\n", - "\n", + " # Trains the discriminator\n", " with tf.GradientTape() as tape:\n", " predictions = self.discriminator(combined_images)\n", " d_loss = self.loss_fn(labels, predictions)\n", @@ -1322,10 +1327,13 @@ " self.d_optimizer.apply_gradients( \n", " zip(grads, self.discriminator.trainable_weights)\n", " )\n", + " # Samples random points in the latent space\n", " random_latent_vectors = tf.random.normal(\n", " shape=(batch_size, self.latent_dim))\n", + " # Assembles labels that say “these are all real images†(it’s a lie!)\n", " misleading_labels = tf.zeros((batch_size, 1))\n", "\n", + " # Trains the generator\n", " with tf.GradientTape() as tape:\n", " predictions = self.discriminator(\n", " self.generator(random_latent_vectors))\n", -- GitLab