Unverified Commit d4265859 authored by Kai Chen's avatar Kai Chen Committed by GitHub
Browse files

Support str type for loggers (#39)

* fix the time estimation when resuming from a checkpoint

* fix the time estimation when resuming from a checkpoint

* support str type for loggers

* fix yaml dump tests
parent b0f40396
......@@ -171,4 +171,7 @@ class PaviLoggerHook(LoggerHook):
log_outs = runner.log_buffer.output.copy()
log_outs.pop('time', None)
log_outs.pop('data_time', None)
for k, v in log_outs.items():
if isinstance(v, str):
log_outs.pop(k)
self.pavi.log(runner.mode, runner.iter + 1, log_outs)
......@@ -33,8 +33,12 @@ class TensorboardLoggerHook(LoggerHook):
if var in ['time', 'data_time']:
continue
tag = '{}/{}'.format(var, runner.mode)
self.writer.add_scalar(tag, runner.log_buffer.output[var],
runner.iter)
record = runner.log_buffer.output[var]
if isinstance(record, str):
self.writer.add_text(tag, record, runner.iter)
else:
self.writer.add_scalar(tag, runner.log_buffer.output[var],
runner.iter)
@master_only
def after_run(self, runner):
......
......@@ -38,6 +38,8 @@ class TextLoggerHook(LoggerHook):
for name, val in runner.log_buffer.output.items():
if name in ['time', 'data_time']:
continue
log_items.append('{}: {:.4f}'.format(name, val))
if isinstance(val, float):
val = '{:.4f}'.format(val)
log_items.append('{}: {}'.format(name, val))
log_str += ', '.join(log_items)
runner.logger.info(log_str)
......@@ -56,7 +56,8 @@ def test_yaml():
def yaml_checker(dump_str):
assert dump_str in [
'- {a: abc, b: 1}\n- 2\n- c\n', '- {b: 1, a: abc}\n- 2\n- c\n'
'- {a: abc, b: 1}\n- 2\n- c\n', '- {b: 1, a: abc}\n- 2\n- c\n',
'- a: abc\n b: 1\n- 2\n- c\n', '- b: 1\n a: abc\n- 2\n- c\n'
]
_test_handler('yaml', obj_for_test, yaml_checker)
......
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