"tests/git@developer.sourcefind.cn:OpenDAS/mmcv.git" did not exist on "a848ecfdfcd5bf7f47e20c900ee046976b1e5d69"
Commit 0505b99c authored by Neal Wu's avatar Neal Wu Committed by GitHub
Browse files

Merge pull request #1127 from AsterAI/fix_cifar_logs

1. Little bit optimized code
parents f7ff5949 74ad728e
...@@ -52,6 +52,8 @@ tf.app.flags.DEFINE_integer('max_steps', 1000000, ...@@ -52,6 +52,8 @@ tf.app.flags.DEFINE_integer('max_steps', 1000000,
"""Number of batches to run.""") """Number of batches to run.""")
tf.app.flags.DEFINE_boolean('log_device_placement', False, tf.app.flags.DEFINE_boolean('log_device_placement', False,
"""Whether to log device placement.""") """Whether to log device placement.""")
tf.app.flags.DEFINE_integer('log_frequency', 10,
"""How often to log results to the console.""")
def train(): def train():
...@@ -78,19 +80,21 @@ def train(): ...@@ -78,19 +80,21 @@ def train():
def begin(self): def begin(self):
self._step = -1 self._step = -1
self._start_time = time.time()
def before_run(self, run_context): def before_run(self, run_context):
self._step += 1 self._step += 1
self._start_time = time.time()
return tf.train.SessionRunArgs(loss) # Asks for loss value. return tf.train.SessionRunArgs(loss) # Asks for loss value.
def after_run(self, run_context, run_values): def after_run(self, run_context, run_values):
duration = time.time() - self._start_time if self._step % FLAGS.log_frequency == 0:
loss_value = run_values.results current_time = time.time()
if self._step % 10 == 0: duration = current_time - self._start_time
num_examples_per_step = FLAGS.batch_size self._start_time = current_time
examples_per_sec = num_examples_per_step / duration
sec_per_batch = float(duration) loss_value = run_values.results
examples_per_sec = FLAGS.log_frequency * FLAGS.batch_size / duration
sec_per_batch = float(duration / FLAGS.log_frequency)
format_str = ('%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' format_str = ('%s: step %d, loss = %.2f (%.1f examples/sec; %.3f '
'sec/batch)') 'sec/batch)')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment