Skip to content
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

Adjust demo scripts to be Keras 3 compatible #6761

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions tensorboard/plugins/graph/graphs_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def keras():
model = tf.keras.models.Sequential(layers)
model.compile(
loss=tf.keras.losses.mean_squared_error,
optimizer=tf.keras.optimizers.SGD(lr=0.2),
optimizer=tf.keras.optimizers.SGD(learning_rate=0.2),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addresses this error:

  File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/optimizers/base_optimizer.py", line 38, in __init__
    raise ValueError(f"Argument(s) not recognized: {kwargs}")
ValueError: Argument(s) not recognized: {'lr': 0.2}

)
model.fit(
x_train,
Expand Down Expand Up @@ -125,11 +125,9 @@ def g(i):
for step in range(3):
# Suppress the profiler deprecation warnings from tf.summary.trace_*.
with _silence_deprecation_warnings():
tf.summary.trace_on(profiler=True)
tf.summary.trace_on(profiler=True, profiler_outdir=logdir)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addresses this error:

WARNING:tensorflow:No `profiler_outdir` passed to trace_on(). Profiler won't be enabled.
0
WARNING:tensorflow:Ignoring `profiler_outdir` passed to trace_export(). Please pass it to trace_on() instead.

<snip>

  File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/tensorflow/python/profiler/profiler_v2.py", line 144, in stop
    raise errors.UnavailableError(
tensorflow.python.framework.errors_impl.UnavailableError: Cannot export profiling results. No profiler is running.

print(f(tf.constant(step)).numpy())
tf.summary.trace_export(
"prof_f", step=step, profiler_outdir=logdir
)
tf.summary.trace_export("prof_f", step=step)

tf.summary.trace_on(profiler=False)
print(g(tf.constant(step)).numpy())
Expand Down
6 changes: 5 additions & 1 deletion tensorboard/plugins/hparams/hparams_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def model_fn(hparams, seed):
conv_filters *= 2

model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dropout(hparams[HP_DROPOUT], seed=rng.random()))
model.add(
tf.keras.layers.Dropout(
hparams[HP_DROPOUT], seed=rng.randrange(1 << 32)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addresses this error:

  File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/layers/regularization/dropout.py", line 53, in __init__
    self.seed_generator = backend.random.SeedGenerator(seed)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/random/seed_generator.py", line 61, in __init__
    raise ValueError(
ValueError: Argument `seed` must be an integer. Received: seed=0.3616904771377427

)
)

# Add fully connected layers.
dense_neurons = 32
Expand Down
Loading