Beispiel #1
0
    def test_basic_logging(self):
        v = ScheduledVariable('v', 1.)

        logger = MetricLogger()
        self.assertEqual(logger.format_logs(), '')

        with self.test_session() as sess:
            ensure_variables_initialized()
            logger.collect_metrics(dict(loss=v))
        logger.collect_metrics(dict(loss=2., valid_loss=3., valid_timer=0.1))
        logger.collect_metrics(dict(loss=4., valid_acc=5., train_time=0.2))
        logger.collect_metrics(dict(loss=6., valid_acc=7., train_time=0.3))
        logger.collect_metrics(dict(other_metric=5.))
        self.assertEqual(
            logger.format_logs(),
            'train time: 0.25s (±0.05s); '
            'valid timer: 0.1s; '
            'other metric: 5; '
            'loss: 3.25 (±1.92029); '
            'valid loss: 3; '
            'valid acc: 6 (±1)'
        )

        logger.clear()
        self.assertEqual(logger.format_logs(), '')

        logger.collect_metrics({'loss': 1.})
        self.assertEqual(logger.format_logs(), 'loss: 1')
    def test_basic_logging(self):
        logger = MetricLogger()
        self.assertEqual(logger.format_logs(), '')

        logger.add_metrics(loss=1.)
        logger.add_metrics(loss=2., valid_loss=3., valid_timer=0.1)
        logger.add_metrics(loss=4., valid_acc=5., train_time=0.2)
        logger.add_metrics(loss=6., valid_acc=7., train_time=0.3)
        self.assertEqual(
            logger.format_logs(), 'train time: 0.25 sec (±0.05 sec); '
            'valid timer: 0.1 sec; '
            'loss: 3.25 (±1.92029); '
            'valid loss: 3; '
            'valid acc: 6 (±1)')

        logger.clear()
        self.assertEqual(logger.format_logs(), '')

        logger.add_metrics(metrics={'loss': 1.})
        self.assertEqual(logger.format_logs(), 'loss: 1')
Beispiel #3
0
    def test_basic_logging(self):
        logger = MetricLogger()
        self.assertEqual(logger.format_logs(), '')

        logger.collect_metrics(dict(loss=SimpleDynamicValue(1.)))
        logger.collect_metrics(dict(loss=2., valid_loss=3., valid_timer=0.1))
        logger.collect_metrics(dict(loss=4., valid_acc=5., train_time=0.2))
        logger.collect_metrics(dict(loss=6., valid_acc=7., train_time=0.3))
        logger.collect_metrics(dict(other_metric=5.))
        self.assertEqual(
            logger.format_logs(), 'train time: 0.25 sec (±0.05 sec); '
            'valid timer: 0.1 sec; '
            'loss: 3.25 (±1.92029); '
            'valid loss: 3; '
            'valid acc: 6 (±1); '
            'other metric: 5')

        logger.clear()
        self.assertEqual(logger.format_logs(), '')

        logger.collect_metrics({'loss': 1.})
        self.assertEqual(logger.format_logs(), 'loss: 1')