From c50cb5e2f5f5e1d605e7ee52dd28c504cc3e893d Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Sun, 9 Jan 2022 13:49:47 +0000 Subject: [PATCH 01/15] add SegmindLoggerHook --- mmcv/runner/hooks/logger/segmind.py | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 mmcv/runner/hooks/logger/segmind.py diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py new file mode 100644 index 0000000000..f287a65b3e --- /dev/null +++ b/mmcv/runner/hooks/logger/segmind.py @@ -0,0 +1,52 @@ +# Copyright (c) OpenMMLab. All rights reserved. +import numbers + +from ...dist_utils import master_only +from ..hook import HOOKS +from .base import LoggerHook + + +@HOOKS.register_module() +class SegmindLoggerHook(LoggerHook): + def __init__( + self, init_kwargs=None, interval=10, ignore_last=True, reset_flag=True + ): + super(SegmindLoggerHook, self).__init__(interval, ignore_last, reset_flag) + self.import_segmind() + + def import_segmind(self): + try: + import segmind + from segmind.tracking.fluent import log_metrics + from segmind.utils.logging_utils import try_mlflow_log + except ImportError: + raise ImportError('Please run "pip install segmind" to install segmind') + self.segmind = segmind + + @master_only + def before_run(self, runner): + super(SegmindLoggerHook, self).before_run(runner) + if self.segmind is None: + self.import_segmind() + + @master_only + def log(self, runner): + metrics = {} + + for var, val in runner.log_buffer.output.items(): + if var in ["time", "data_time"]: + continue + + tag = f"{var}_{runner.mode}" + if isinstance(val, numbers.Number): + metrics[tag] = val + + metrics["learning_rate"] = runner.current_lr()[0] + metrics["momentum"] = runner.current_momentum()[0] + + # logging metrics to segmind + try_mlflow_log(log_metrics, metrics, step=runner.epoch, epoch=runner.epoch) + + @master_only + def after_run(self, runner): + pass From 1c468ff75025d62eedb8fed1c54b4744825ff4f9 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Sun, 9 Jan 2022 16:55:43 +0000 Subject: [PATCH 02/15] update linting for segmind.py --- mmcv/runner/hooks/logger/segmind.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index f287a65b3e..abbb81df35 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -11,7 +11,8 @@ class SegmindLoggerHook(LoggerHook): def __init__( self, init_kwargs=None, interval=10, ignore_last=True, reset_flag=True ): - super(SegmindLoggerHook, self).__init__(interval, ignore_last, reset_flag) + super(SegmindLoggerHook, self).__init__( + interval, ignore_last, reset_flag) self.import_segmind() def import_segmind(self): @@ -20,8 +21,11 @@ def import_segmind(self): from segmind.tracking.fluent import log_metrics from segmind.utils.logging_utils import try_mlflow_log except ImportError: - raise ImportError('Please run "pip install segmind" to install segmind') + raise ImportError("Please run 'pip install segmind' to install \ + segmind") self.segmind = segmind + self.log_metrics = log_metrics + self.try_mlflow_log = try_mlflow_log @master_only def before_run(self, runner): @@ -45,7 +49,12 @@ def log(self, runner): metrics["momentum"] = runner.current_momentum()[0] # logging metrics to segmind - try_mlflow_log(log_metrics, metrics, step=runner.epoch, epoch=runner.epoch) + self.try_mlflow_log( + self.log_metrics, + metrics, + step=runner.epoch, + epoch=runner.epoch + ) @master_only def after_run(self, runner): From 71b348b11130ceacfd6452a4d3ddd55500536018 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Sun, 9 Jan 2022 17:18:06 +0000 Subject: [PATCH 03/15] ran pre-commit --- mmcv/runner/hooks/logger/segmind.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index abbb81df35..f0917b2c91 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -8,11 +8,14 @@ @HOOKS.register_module() class SegmindLoggerHook(LoggerHook): - def __init__( - self, init_kwargs=None, interval=10, ignore_last=True, reset_flag=True - ): - super(SegmindLoggerHook, self).__init__( - interval, ignore_last, reset_flag) + + def __init__(self, + init_kwargs=None, + interval=10, + ignore_last=True, + reset_flag=True): + super(SegmindLoggerHook, self).__init__(interval, ignore_last, + reset_flag) self.import_segmind() def import_segmind(self): @@ -38,23 +41,19 @@ def log(self, runner): metrics = {} for var, val in runner.log_buffer.output.items(): - if var in ["time", "data_time"]: + if var in ['time', 'data_time']: continue - tag = f"{var}_{runner.mode}" + tag = f'{var}_{runner.mode}' if isinstance(val, numbers.Number): metrics[tag] = val - metrics["learning_rate"] = runner.current_lr()[0] - metrics["momentum"] = runner.current_momentum()[0] + metrics['learning_rate'] = runner.current_lr()[0] + metrics['momentum'] = runner.current_momentum()[0] # logging metrics to segmind self.try_mlflow_log( - self.log_metrics, - metrics, - step=runner.epoch, - epoch=runner.epoch - ) + self.log_metrics, metrics, step=runner.epoch, epoch=runner.epoch) @master_only def after_run(self, runner): From 8cb559bfebfa5dd0fc6e65608334175ab33ac27d Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Mon, 10 Jan 2022 11:21:11 +0000 Subject: [PATCH 04/15] add test_segmind_hook - add SegmindLoggerHook import in: mmcv/runner/__init__.py mmcv/runner/hooks/__init__.py mmcv/runner/hooks/logger/__init__.py --- mmcv/runner/__init__.py | 8 +++++--- mmcv/runner/hooks/__init__.py | 7 ++++--- mmcv/runner/hooks/logger/__init__.py | 3 ++- tests/test_runner/test_hooks.py | 22 +++++++++++++++++++++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/mmcv/runner/__init__.py b/mmcv/runner/__init__.py index e9b41a64c4..bba39f5c90 100644 --- a/mmcv/runner/__init__.py +++ b/mmcv/runner/__init__.py @@ -15,8 +15,9 @@ Fp16OptimizerHook, GradientCumulativeFp16OptimizerHook, GradientCumulativeOptimizerHook, Hook, IterTimerHook, LoggerHook, MlflowLoggerHook, NeptuneLoggerHook, - OptimizerHook, PaviLoggerHook, SyncBuffersHook, - TensorboardLoggerHook, TextLoggerHook, WandbLoggerHook) + OptimizerHook, PaviLoggerHook, SegmindLoggerHook, + SyncBuffersHook, TensorboardLoggerHook, TextLoggerHook, + WandbLoggerHook) from .hooks.lr_updater import StepLrUpdaterHook # noqa from .hooks.lr_updater import (CosineAnnealingLrUpdaterHook, CosineRestartLrUpdaterHook, CyclicLrUpdaterHook, @@ -60,5 +61,6 @@ 'allreduce_params', 'LossScaler', 'CheckpointLoader', 'BaseModule', '_load_checkpoint_with_prefix', 'EvalHook', 'DistEvalHook', 'Sequential', 'ModuleDict', 'ModuleList', 'GradientCumulativeOptimizerHook', - 'GradientCumulativeFp16OptimizerHook', 'DefaultRunnerConstructor' + 'GradientCumulativeFp16OptimizerHook', 'DefaultRunnerConstructor', + 'SegmindLoggerHook' ] diff --git a/mmcv/runner/hooks/__init__.py b/mmcv/runner/hooks/__init__.py index 671bb0c2e9..121073eb58 100644 --- a/mmcv/runner/hooks/__init__.py +++ b/mmcv/runner/hooks/__init__.py @@ -6,8 +6,8 @@ from .hook import HOOKS, Hook from .iter_timer import IterTimerHook from .logger import (DvcliveLoggerHook, LoggerHook, MlflowLoggerHook, - NeptuneLoggerHook, PaviLoggerHook, TensorboardLoggerHook, - TextLoggerHook, WandbLoggerHook) + NeptuneLoggerHook, PaviLoggerHook, SegmindLoggerHook, + TensorboardLoggerHook, TextLoggerHook, WandbLoggerHook) from .lr_updater import (CosineAnnealingLrUpdaterHook, CosineRestartLrUpdaterHook, CyclicLrUpdaterHook, ExpLrUpdaterHook, FixedLrUpdaterHook, @@ -38,5 +38,6 @@ 'StepMomentumUpdaterHook', 'CosineAnnealingMomentumUpdaterHook', 'CyclicMomentumUpdaterHook', 'OneCycleMomentumUpdaterHook', 'SyncBuffersHook', 'EMAHook', 'EvalHook', 'DistEvalHook', 'ProfilerHook', - 'GradientCumulativeOptimizerHook', 'GradientCumulativeFp16OptimizerHook' + 'GradientCumulativeOptimizerHook', 'GradientCumulativeFp16OptimizerHook', + 'SegmindLoggerHook' ] diff --git a/mmcv/runner/hooks/logger/__init__.py b/mmcv/runner/hooks/logger/__init__.py index a0b6b34564..8ce580d392 100644 --- a/mmcv/runner/hooks/logger/__init__.py +++ b/mmcv/runner/hooks/logger/__init__.py @@ -4,6 +4,7 @@ from .mlflow import MlflowLoggerHook from .neptune import NeptuneLoggerHook from .pavi import PaviLoggerHook +from .segmind import SegmindLoggerHook from .tensorboard import TensorboardLoggerHook from .text import TextLoggerHook from .wandb import WandbLoggerHook @@ -11,5 +12,5 @@ __all__ = [ 'LoggerHook', 'MlflowLoggerHook', 'PaviLoggerHook', 'TensorboardLoggerHook', 'TextLoggerHook', 'WandbLoggerHook', - 'NeptuneLoggerHook', 'DvcliveLoggerHook' + 'NeptuneLoggerHook', 'DvcliveLoggerHook', 'SegmindLoggerHook' ] diff --git a/tests/test_runner/test_hooks.py b/tests/test_runner/test_hooks.py index c628fa78d9..c39855a96f 100644 --- a/tests/test_runner/test_hooks.py +++ b/tests/test_runner/test_hooks.py @@ -26,7 +26,8 @@ GradientCumulativeFp16OptimizerHook, GradientCumulativeOptimizerHook, IterTimerHook, MlflowLoggerHook, NeptuneLoggerHook, OptimizerHook, - PaviLoggerHook, WandbLoggerHook, build_runner) + PaviLoggerHook, SegmindLoggerHook, WandbLoggerHook, + build_runner) from mmcv.runner.fp16_utils import auto_fp16 from mmcv.runner.hooks.hook import HOOKS, Hook from mmcv.runner.hooks.lr_updater import (CosineRestartLrUpdaterHook, @@ -1189,6 +1190,25 @@ def test_mlflow_hook(log_model): assert not hook.mlflow_pytorch.log_model.called +def test_segmind_hook(): + sys.modules['segmind'] = MagicMock() + runner = _build_demo_runner() + hook = SegmindLoggerHook() + loader = DataLoader(torch.ones((5, 2))) + + runner.register_hook(hook) + runner.run([loader, loader], [('train', 1), ('val', 1)]) + shutil.rmtree(runner.work_dir) + + hook.segmind.init.assert_called_with() + hook.segmind.log.assert_called_with( + { + 'learning_rate': 0.02, + 'momentum': 0.95 + }, step=6, commit=True) + hook.segmind.join.assert_called_with() + + def test_wandb_hook(): sys.modules['wandb'] = MagicMock() runner = _build_demo_runner() From dcf7810052288bd37343e223c47001f2ac5c5513 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Mon, 10 Jan 2022 13:42:09 +0000 Subject: [PATCH 05/15] update test_segmind_hook - Add Docstring to SegmindLoggerHook - Use get_loggable_tags(...) --- mmcv/runner/hooks/logger/segmind.py | 41 +++++++++++------------------ tests/test_runner/test_hooks.py | 12 ++++----- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index f0917b2c91..8b106df193 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -1,6 +1,4 @@ # Copyright (c) OpenMMLab. All rights reserved. -import numbers - from ...dist_utils import master_only from ..hook import HOOKS from .base import LoggerHook @@ -9,13 +7,15 @@ @HOOKS.register_module() class SegmindLoggerHook(LoggerHook): - def __init__(self, - init_kwargs=None, - interval=10, - ignore_last=True, - reset_flag=True): - super(SegmindLoggerHook, self).__init__(interval, ignore_last, - reset_flag) + def __init__(self): + """Class to log metrics to Segmind. + + It requires `Segmind`_ to be installed. + + .. Segmind: + https://docs.segmind.com/python-library + """ + super(SegmindLoggerHook, self).__init__() self.import_segmind() def import_segmind(self): @@ -28,7 +28,7 @@ def import_segmind(self): segmind") self.segmind = segmind self.log_metrics = log_metrics - self.try_mlflow_log = try_mlflow_log + self.segmind_log = try_mlflow_log @master_only def before_run(self, runner): @@ -38,22 +38,11 @@ def before_run(self, runner): @master_only def log(self, runner): - metrics = {} - - for var, val in runner.log_buffer.output.items(): - if var in ['time', 'data_time']: - continue - - tag = f'{var}_{runner.mode}' - if isinstance(val, numbers.Number): - metrics[tag] = val - - metrics['learning_rate'] = runner.current_lr()[0] - metrics['momentum'] = runner.current_momentum()[0] - - # logging metrics to segmind - self.try_mlflow_log( - self.log_metrics, metrics, step=runner.epoch, epoch=runner.epoch) + tags = self.get_loggable_tags(runner) + if tags: + # logging metrics to segmind + self.segmind_log( + self.log_metrics, tags, step=runner.epoch, epoch=runner.epoch) @master_only def after_run(self, runner): diff --git a/tests/test_runner/test_hooks.py b/tests/test_runner/test_hooks.py index c39855a96f..cc782e5fd9 100644 --- a/tests/test_runner/test_hooks.py +++ b/tests/test_runner/test_hooks.py @@ -21,13 +21,11 @@ from torch.utils.data import DataLoader from mmcv.fileio.file_client import PetrelBackend -from mmcv.runner import (CheckpointHook, DvcliveLoggerHook, EMAHook, - Fp16OptimizerHook, - GradientCumulativeFp16OptimizerHook, - GradientCumulativeOptimizerHook, IterTimerHook, - MlflowLoggerHook, NeptuneLoggerHook, OptimizerHook, - PaviLoggerHook, SegmindLoggerHook, WandbLoggerHook, - build_runner) +from mmcv.runner import ( + CheckpointHook, DvcliveLoggerHook, EMAHook, Fp16OptimizerHook, + GradientCumulativeFp16OptimizerHook, GradientCumulativeOptimizerHook, + IterTimerHook, MlflowLoggerHook, NeptuneLoggerHook, OptimizerHook, + PaviLoggerHook, SegmindLoggerHook, WandbLoggerHook, build_runner) from mmcv.runner.fp16_utils import auto_fp16 from mmcv.runner.hooks.hook import HOOKS, Hook from mmcv.runner.hooks.lr_updater import (CosineRestartLrUpdaterHook, From 00ab38764b30ce7a55bae70735b514ba7df5e912 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Tue, 11 Jan 2022 15:31:22 +0000 Subject: [PATCH 06/15] update test_hooks.py & segmind.py - mmcv/runner/hooks/logger/segmind.py moved docs from __init__ to class ... update ImportError line-indentation remove unwanted method - tests/test_runner/test_hooks.py update assert_called_with only on hook.segmind_mlflow_log --- mmcv/runner/hooks/logger/segmind.py | 31 ++++++++++++++--------------- tests/test_runner/test_hooks.py | 10 +++++----- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index 8b106df193..d246dcb24d 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -6,15 +6,15 @@ @HOOKS.register_module() class SegmindLoggerHook(LoggerHook): + """Class to log metrics to Segmind. - def __init__(self): - """Class to log metrics to Segmind. + It requires `Segmind`_ to be installed. - It requires `Segmind`_ to be installed. + .. Segmind: + https://docs.segmind.com/python-library + """ - .. Segmind: - https://docs.segmind.com/python-library - """ + def __init__(self): super(SegmindLoggerHook, self).__init__() self.import_segmind() @@ -24,11 +24,11 @@ def import_segmind(self): from segmind.tracking.fluent import log_metrics from segmind.utils.logging_utils import try_mlflow_log except ImportError: - raise ImportError("Please run 'pip install segmind' to install \ - segmind") + raise ImportError( + "Please run 'pip install segmind' to install segmind") self.segmind = segmind - self.log_metrics = log_metrics - self.segmind_log = try_mlflow_log + self.segmind_log_metrics = log_metrics + self.segmind_mlflow_log = try_mlflow_log @master_only def before_run(self, runner): @@ -41,9 +41,8 @@ def log(self, runner): tags = self.get_loggable_tags(runner) if tags: # logging metrics to segmind - self.segmind_log( - self.log_metrics, tags, step=runner.epoch, epoch=runner.epoch) - - @master_only - def after_run(self, runner): - pass + self.segmind_mlflow_log( + self.segmind_log_metrics, + tags, + step=runner.epoch, + epoch=runner.epoch) diff --git a/tests/test_runner/test_hooks.py b/tests/test_runner/test_hooks.py index cc782e5fd9..6c7fcaef62 100644 --- a/tests/test_runner/test_hooks.py +++ b/tests/test_runner/test_hooks.py @@ -1198,13 +1198,13 @@ def test_segmind_hook(): runner.run([loader, loader], [('train', 1), ('val', 1)]) shutil.rmtree(runner.work_dir) - hook.segmind.init.assert_called_with() - hook.segmind.log.assert_called_with( - { + hook.segmind_mlflow_log.assert_called_with( + hook.segmind_log_metrics, { 'learning_rate': 0.02, 'momentum': 0.95 - }, step=6, commit=True) - hook.segmind.join.assert_called_with() + }, + step=runner.epoch, + epoch=runner.epoch) def test_wandb_hook(): From cb897e4c728a29f41bdfe1971749ed2df31224c9 Mon Sep 17 00:00:00 2001 From: saurbhc Date: Thu, 13 Jan 2022 16:11:17 +0000 Subject: [PATCH 07/15] Update tests/test_runner/test_hooks.py disable yapf on test_hooks.py imports Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com> --- tests/test_runner/test_hooks.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_runner/test_hooks.py b/tests/test_runner/test_hooks.py index 6c7fcaef62..f4f01d9382 100644 --- a/tests/test_runner/test_hooks.py +++ b/tests/test_runner/test_hooks.py @@ -21,11 +21,15 @@ from torch.utils.data import DataLoader from mmcv.fileio.file_client import PetrelBackend -from mmcv.runner import ( - CheckpointHook, DvcliveLoggerHook, EMAHook, Fp16OptimizerHook, - GradientCumulativeFp16OptimizerHook, GradientCumulativeOptimizerHook, - IterTimerHook, MlflowLoggerHook, NeptuneLoggerHook, OptimizerHook, - PaviLoggerHook, SegmindLoggerHook, WandbLoggerHook, build_runner) +# yapf: disable +from mmcv.runner import (CheckpointHook, DvcliveLoggerHook, EMAHook, + Fp16OptimizerHook, + GradientCumulativeFp16OptimizerHook, + GradientCumulativeOptimizerHook, IterTimerHook, + MlflowLoggerHook, NeptuneLoggerHook, OptimizerHook, + PaviLoggerHook, SegmindLoggerHook, WandbLoggerHook, + build_runner) +# yapf: enable from mmcv.runner.fp16_utils import auto_fp16 from mmcv.runner.hooks.hook import HOOKS, Hook from mmcv.runner.hooks.lr_updater import (CosineRestartLrUpdaterHook, From 21d8d64f304b5cad9dab2af398f297397c37c552 Mon Sep 17 00:00:00 2001 From: saurbhc Date: Thu, 13 Jan 2022 16:14:18 +0000 Subject: [PATCH 08/15] Update mmcv/runner/hooks/logger/segmind.py Update SegmindLoggerHook docstring Co-authored-by: Jiazhen Wang <47851024+teamwong111@users.noreply.github.com> --- mmcv/runner/hooks/logger/segmind.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index d246dcb24d..5aac348253 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -10,7 +10,7 @@ class SegmindLoggerHook(LoggerHook): It requires `Segmind`_ to be installed. - .. Segmind: + .. _Segmind: https://docs.segmind.com/python-library """ From 6621fab5642762d29289a8ca97bec6f7a5620a57 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Thu, 13 Jan 2022 16:23:38 +0000 Subject: [PATCH 09/15] update before_run method in segmind.py removed un-used statements --- mmcv/runner/hooks/logger/segmind.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index 5aac348253..dcbf7642e8 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -30,12 +30,6 @@ def import_segmind(self): self.segmind_log_metrics = log_metrics self.segmind_mlflow_log = try_mlflow_log - @master_only - def before_run(self, runner): - super(SegmindLoggerHook, self).before_run(runner) - if self.segmind is None: - self.import_segmind() - @master_only def log(self, runner): tags = self.get_loggable_tags(runner) From 0a04ae35224cbfb912a5e5421817298eeb66cfb9 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Thu, 13 Jan 2022 19:43:15 +0000 Subject: [PATCH 10/15] updated imports in SegmindLoggerHook --- mmcv/runner/hooks/logger/segmind.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index dcbf7642e8..f439960b41 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -21,14 +21,12 @@ def __init__(self): def import_segmind(self): try: import segmind - from segmind.tracking.fluent import log_metrics - from segmind.utils.logging_utils import try_mlflow_log except ImportError: raise ImportError( "Please run 'pip install segmind' to install segmind") self.segmind = segmind - self.segmind_log_metrics = log_metrics - self.segmind_mlflow_log = try_mlflow_log + self.segmind_log_metrics = segmind.tracking.fluent.log_metrics + self.segmind_mlflow_log = segmind.utils.logging_utils.try_mlflow_log @master_only def log(self, runner): From 6b1b679879207a3009682fd5e043b91c48a7c6a3 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Sat, 15 Jan 2022 11:24:41 +0000 Subject: [PATCH 11/15] update SegmindLoggerHook - code cleanup --- mmcv/runner/hooks/logger/segmind.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index f439960b41..5311112594 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -24,7 +24,6 @@ def import_segmind(self): except ImportError: raise ImportError( "Please run 'pip install segmind' to install segmind") - self.segmind = segmind self.segmind_log_metrics = segmind.tracking.fluent.log_metrics self.segmind_mlflow_log = segmind.utils.logging_utils.try_mlflow_log From 0ea8ebefa806c9fcd27382b418f773aad948761b Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Wed, 19 Jan 2022 16:53:58 +0000 Subject: [PATCH 12/15] update SegmindLoggerHook - add interval parameter in __init__ method --- mmcv/runner/hooks/logger/segmind.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index 5311112594..c295314ac9 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -10,12 +10,15 @@ class SegmindLoggerHook(LoggerHook): It requires `Segmind`_ to be installed. + Args: + interval (int): Logging interval (every k iterations). Default: 10. + .. _Segmind: https://docs.segmind.com/python-library """ - def __init__(self): - super(SegmindLoggerHook, self).__init__() + def __init__(self, interval=10): + super(SegmindLoggerHook, self).__init__(interval=10) self.import_segmind() def import_segmind(self): From 2aea4a18bca963e4715224db1f50536c36a7bdb4 Mon Sep 17 00:00:00 2001 From: Saurabh Chopra Date: Thu, 20 Jan 2022 12:03:53 +0000 Subject: [PATCH 13/15] update SegmindLoggerHook - more arguments passes to __init__ method - interval - ignore_last - reset_flag - by_epoch --- mmcv/runner/hooks/logger/segmind.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index c295314ac9..b7928fbd5a 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -11,14 +11,24 @@ class SegmindLoggerHook(LoggerHook): It requires `Segmind`_ to be installed. Args: - interval (int): Logging interval (every k iterations). Default: 10. + interval (int): Logging interval (every k iterations). Default: 10. + ignore_last (bool): Ignore the log of last iterations in each epoch + if less than `interval`. Default True. + reset_flag (bool): Whether to clear the output buffer after logging. + Default False. + by_epoch (bool): Whether EpochBasedRunner is used. Default True. .. _Segmind: https://docs.segmind.com/python-library """ - def __init__(self, interval=10): - super(SegmindLoggerHook, self).__init__(interval=10) + def __init__(self, + interval=10, + ignore_last=True, + reset_flag=False, + by_epoch=True): + super(SegmindLoggerHook, self).__init__(interval, ignore_last, + reset_flag, by_epoch) self.import_segmind() def import_segmind(self): From 2ef26903d5befc476867c3223137af6ed8a65e3f Mon Sep 17 00:00:00 2001 From: saurbhc Date: Wed, 23 Feb 2022 12:30:20 +0000 Subject: [PATCH 14/15] Update mmcv/runner/hooks/logger/segmind.py Co-authored-by: Mashiro <57566630+HAOCHENYE@users.noreply.github.com> --- mmcv/runner/hooks/logger/segmind.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index b7928fbd5a..792f758832 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -45,7 +45,7 @@ def log(self, runner): tags = self.get_loggable_tags(runner) if tags: # logging metrics to segmind - self.segmind_mlflow_log( + self.mlflow_log( self.segmind_log_metrics, tags, step=runner.epoch, From 86b4454886c64481414cac7b162ca0482cfda485 Mon Sep 17 00:00:00 2001 From: saurbhc Date: Wed, 23 Feb 2022 12:30:50 +0000 Subject: [PATCH 15/15] Update mmcv/runner/hooks/logger/segmind.py Co-authored-by: Mashiro <57566630+HAOCHENYE@users.noreply.github.com> --- mmcv/runner/hooks/logger/segmind.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mmcv/runner/hooks/logger/segmind.py b/mmcv/runner/hooks/logger/segmind.py index 792f758832..3c7e6d831f 100644 --- a/mmcv/runner/hooks/logger/segmind.py +++ b/mmcv/runner/hooks/logger/segmind.py @@ -37,8 +37,8 @@ def import_segmind(self): except ImportError: raise ImportError( "Please run 'pip install segmind' to install segmind") - self.segmind_log_metrics = segmind.tracking.fluent.log_metrics - self.segmind_mlflow_log = segmind.utils.logging_utils.try_mlflow_log + self.log_metrics = segmind.tracking.fluent.log_metrics + self.mlflow_log = segmind.utils.logging_utils.try_mlflow_log @master_only def log(self, runner):