-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Fix TensorBoard callback step counter never updating #22357
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
Draft
pctablet505
wants to merge
1
commit into
keras-team:master
Choose a base branch
from
pctablet505:fix/20143-tensorboard-step-counter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,16 +310,16 @@ def _configure_embeddings(self): | |
| with file_utils.File(path, "w") as f: | ||
| f.write(config_pbtxt) | ||
|
|
||
| def _push_writer(self, writer, step): | ||
| def _push_writer(self, writer, step_var): | ||
| """Sets the default writer for custom batch-level summaries.""" | ||
| if self.update_freq == "epoch": | ||
| return | ||
|
|
||
| def should_record(): | ||
| return step % self.update_freq == 0 | ||
| return step_var % self.update_freq == 0 | ||
|
|
||
| summary_context = ( | ||
| writer.as_default(step), | ||
| writer.as_default(step_var), | ||
| self.summary.record_if(should_record), | ||
| ) | ||
| self._prev_summary_state.append(summary_context) | ||
|
|
@@ -404,9 +404,12 @@ def _init_profile_batch(self, profile_batch): | |
| ) | ||
|
|
||
| def on_train_begin(self, logs=None): | ||
| import tensorflow as tf | ||
|
|
||
| self._global_train_batch = 0 | ||
| self._previous_epoch_iterations = 0 | ||
| self._push_writer(self._train_writer, self._global_train_batch) | ||
| self._train_step_var = tf.Variable(0, dtype=tf.int64, trainable=False) | ||
| self._push_writer(self._train_writer, self._train_step_var) | ||
|
|
||
| def on_train_end(self, logs=None): | ||
| self._pop_writer() | ||
|
|
@@ -417,7 +420,10 @@ def on_train_end(self, logs=None): | |
| self._close_writers() | ||
|
|
||
| def on_test_begin(self, logs=None): | ||
| self._push_writer(self._val_writer, self._global_test_batch) | ||
| import tensorflow as tf | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| self._test_step_var = tf.Variable(0, dtype=tf.int64, trainable=False) | ||
| self._push_writer(self._val_writer, self._test_step_var) | ||
|
|
||
| def on_test_end(self, logs=None): | ||
| if self.model.optimizer and hasattr(self.model.optimizer, "iterations"): | ||
|
|
@@ -432,6 +438,8 @@ def on_test_end(self, logs=None): | |
|
|
||
| def on_train_batch_begin(self, batch, logs=None): | ||
| self._global_train_batch += 1 | ||
| if hasattr(self, "_train_step_var"): | ||
| self._train_step_var.assign(self._global_train_batch) | ||
| if self.write_steps_per_second: | ||
| self._batch_start_time = time.time() | ||
| if not self._should_trace: | ||
|
|
@@ -475,6 +483,8 @@ def on_train_batch_end(self, batch, logs=None): | |
|
|
||
| def on_test_batch_begin(self, batch, logs=None): | ||
| self._global_test_batch += 1 | ||
| if hasattr(self, "_test_step_var"): | ||
| self._test_step_var.assign(self._global_test_batch) | ||
|
|
||
| def on_epoch_begin(self, epoch, logs=None): | ||
| # Keeps track of epoch for profiling. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This
import tensorflow as tfstatement is also present inon_test_begin. To avoid duplication and improve maintainability, consider importingtensorflowonce at the top of the file using the Keras-idiomatic lazy loader:This would allow you to remove the local imports from both
on_train_beginandon_test_begin.