-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add global_counter to Trainer as optional argument #271
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,15 +56,15 @@ class Trainer(object): | |
achieved before a model weight's are saved to the best_checkpoint_path. This | ||
allows the user to skip early saves and also set a minimum save point when continuing | ||
to train a reloaded model. Default: 0.0. | ||
|
||
global_counter: `int`. A Tensorflow variable to hold a global counter of the update steps. | ||
""" | ||
|
||
def __init__(self, train_ops, graph=None, clip_gradients=5.0, | ||
tensorboard_dir="/tmp/tflearn_logs/", | ||
tensorboard_verbose=0, checkpoint_path=None, best_checkpoint_path=None, | ||
max_checkpoints=None, | ||
keep_checkpoint_every_n_hours=10000.0, random_seed=None, | ||
session=None, best_val_accuracy=0.0): | ||
session=None, best_val_accuracy=0.0, global_step=None): | ||
|
||
self.graph = tf.get_default_graph() | ||
if graph: | ||
|
@@ -87,8 +87,11 @@ def __init__(self, train_ops, graph=None, clip_gradients=5.0, | |
self.validate_trainop_names() | ||
|
||
self.global_loss = None | ||
self.global_step = tf.Variable(0., name='Global_Step', | ||
trainable=False) | ||
if global_step: | ||
self.global_step = global_step | ||
else: | ||
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. This can be simplified into just checking if global_step = none and if so we create the new variable then assign it to self at the end. 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. Something like self.global_step = tf.Var if global_step is None else global_step 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. I thought about that but putting everything in one line might hurt readability: after all, the definition of tf.Variable(...) is already taking two lines. 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. Sure, that makes sense. I was thinking more like we don't need the entire if else. It can be something like:
but your way is more explicit. |
||
self.global_step = tf.Variable(0., name='Global_Step', | ||
trainable=False) | ||
self.incr_global_step = tf.assign(self.global_step, | ||
tf.add(self.global_step, 1)) | ||
self.best_val_accuracy = best_val_accuracy | ||
|
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.
Here you need to set:
because 'if
Tensor
' raises an exception in TensorFlow.