[FIx] Logging time in LoggerHook.after_val_epoch has no effect (#376)

pull/379/head
Mashiro 2022-07-20 16:51:11 +08:00 committed by GitHub
parent 6b47035fdf
commit 6bd548d8bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 10 deletions

View File

@ -214,10 +214,7 @@ class LoggerHook(Hook):
# by iter. At the same time, scalars related to time should # by iter. At the same time, scalars related to time should
# still be logged by iter to avoid messy visualized result. # still be logged by iter to avoid messy visualized result.
# see details in PR #278. # see details in PR #278.
time_tags = {k: v for k, v in tag.items() if 'time' in k}
metric_tags = {k: v for k, v in tag.items() if 'time' not in k} metric_tags = {k: v for k, v in tag.items() if 'time' not in k}
runner.visualizer.add_scalars(
time_tags, step=runner.iter, file_path=self.json_log_path)
runner.visualizer.add_scalars( runner.visualizer.add_scalars(
metric_tags, step=runner.epoch, file_path=self.json_log_path) metric_tags, step=runner.epoch, file_path=self.json_log_path)
else: else:

View File

@ -128,12 +128,7 @@ class TestLoggerHook:
logger_hook.after_val_epoch(runner) logger_hook.after_val_epoch(runner)
args = {'step': ANY, 'file_path': ANY} args = {'step': ANY, 'file_path': ANY}
# expect visualizer log `time` and `metric` respectively # expect visualizer log `time` and `metric` respectively
runner.visualizer.add_scalars.assert_any_call( runner.visualizer.add_scalars.assert_called_with({'acc': 0.8}, **args)
{
'time': 1,
'datatime': 1
}, **args)
runner.visualizer.add_scalars.assert_any_call({'acc': 0.8}, **args)
# Test when `log_metric_by_epoch` is False # Test when `log_metric_by_epoch` is False
logger_hook = LoggerHook(log_metric_by_epoch=False) logger_hook = LoggerHook(log_metric_by_epoch=False)
@ -145,7 +140,7 @@ class TestLoggerHook:
}, 'string')) }, 'string'))
logger_hook.after_val_epoch(runner) logger_hook.after_val_epoch(runner)
# expect visualizer log `time` and `metric` jointly # expect visualizer log `time` and `metric` jointly
runner.visualizer.add_scalars.assert_any_call( runner.visualizer.add_scalars.assert_called_with(
{ {
'time': 5, 'time': 5,
'datatime': 5, 'datatime': 5,