fix InteractiveLogger (by lrzpellegrini)
# See the accompanying LICENSE file for terms. #
# #
# Date: 2020-01-25 #
-# Author(s): Antonio Carta #
+# Author(s): Antonio Carta, Lorenzo Pellegrini #
# E-mail: contact@continualai.org #
# Website: clair.continualai.org #
################################################################################
@@ -26,29 +26,47 @@ class InteractiveLogger(TextLogger):
bar and prints metric values.
"""
super().__init__(file=sys.stdout)
- self.pbar = tqdm()
+ self._pbar = None
def before_training_epoch(self, strategy: PluggableStrategy,
metric_values: List['MetricValue'], **kwargs):
- print(strategy.mb_it)
super().before_training_epoch(strategy, metric_values, **kwargs)
- self.pbar.reset()
- self.pbar.total = len(strategy.current_dataloader)
+ self._progress.total = len(strategy.current_dataloader)
+
+ def after_training_epoch(self, strategy: PluggableStrategy,
+ metric_values: List['MetricValue'], **kwargs):
+ self._end_progress()
+ super().after_training_epoch(strategy, metric_values, **kwargs)
def before_test_step(self, strategy: PluggableStrategy,
metric_values: List['MetricValue'], **kwargs):
super().before_test_step(strategy, metric_values, **kwargs)
- self.pbar.reset()
- self.pbar.total = len(strategy.current_dataloader)
+ self._progress.total = len(strategy.current_dataloader)
+
+ def after_test_step(self, strategy: 'PluggableStrategy',
+ metric_values: List['MetricValue'], **kwargs):
+ self._end_progress()
+ super().after_test_step(strategy, metric_values, **kwargs)
def after_training_iteration(self, strategy: 'PluggableStrategy',
metric_values: List['MetricValue'], **kwargs):
+ self._progress.update()
+ self._progress.refresh()
super().after_training_iteration(strategy, metric_values, **kwargs)
- self.pbar.update()
- self.pbar.refresh()
def after_test_iteration(self, strategy: 'PluggableStrategy',
metric_values: List['MetricValue'], **kwargs):
+ self._progress.update()
+ self._progress.refresh()
super().after_test_iteration(strategy, metric_values, **kwargs)
- self.pbar.update()
- self.pbar.refresh()
+
+ @property
+ def _progress(self):
+ if self._pbar is None:
+ self._pbar = tqdm(leave=True, position=0, file=sys.stdout)
+ return self._pbar
+
+ def _end_progress(self):
+ if self._pbar is not None:
+ self._pbar.close()
+ self._pbar = None
