-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DCGAN overriding training step- Keras 3 Migration (Only Tensorflow Backend) #1693
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR!
@@ -154,10 +156,10 @@ def train_step(self, real_images): | |||
) | |||
|
|||
# Sample random points in the latent space | |||
random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim)) | |||
random_latent_vectors = keras.random.normal(shape=(batch_size, self.latent_dim)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critically, this needs to be seeded with a SeedGenerator
instance attached to the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, made the required changes
import matplotlib.pyplot as plt | ||
import os | ||
import gdown | ||
from zipfile import ZipFile | ||
|
||
seed_generator = keras.random.SeedGenerator(42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The seed generator must be attached to the layer. So you should do:
class GAN(keras.Model):
def __init__(self, **kwargs):
...
self.seed_generator = keras.random.SeedGenerator(1337)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it
@@ -185,9 +193,13 @@ class GANMonitor(keras.callbacks.Callback): | |||
def __init__(self, num_img=3, latent_dim=128): | |||
self.num_img = num_img | |||
self.latent_dim = latent_dim | |||
self.seed_generator = keras.random.SeedGenerator(42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope this is the correct way to declare for epoch end random number generation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good! Please regenerate the other files.
Retrained and generated the required files, Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
…ckend) (keras-team#1693) * Migrate to Keras 3 * Keras 3 Migration * Add seed generator to keras.random * Train using seed generator * Update dcgan_overriding_train_step.py * Rgenerate files * Migration to Keras 3 * Revert "Migration to Keras 3" This reverts commit 7b003f5.
DCGAN overriding training step- Keras 3 Migration (Only Tensorflow Backend) fix it - KerasCV-Fixit