示例#1
0
    def test_continuous_eval_evaluates_checkpoint_once(self):
        for est in self._estimators_for_tests(eval_dict={'global_step': 100}):
            est.fake_checkpoint()

            result = {
                'called': 0,
                'called_with_eval_result': 0,
            }

            # pylint: disable=cell-var-from-loop
            def _predicate_fn(eval_result):
                result['called'] += 1
                if eval_result:
                    # If eval_result is not empty nor None, the checkpoint has been
                    # evaluated.
                    result['called_with_eval_result'] += 1
                # With 300 times of evaluation, this should prove something.
                return result['called'] < 300

            # pylint: enable=cell-var-from-loop

            ex = Experiment(est,
                            train_input_fn='train_input',
                            eval_input_fn='eval_input',
                            eval_delay_secs=0,
                            continuous_eval_throttle_secs=0)
            ex.continuous_eval(evaluate_checkpoint_only_once=True,
                               continuous_eval_predicate_fn=_predicate_fn)

            self.assertEqual(0, est.fit_count)
            self.assertEqual(1, est.eval_count)
            self.assertEqual(300, result['called'])
            self.assertEqual(1, result['called_with_eval_result'])
示例#2
0
    def test_continuous_eval_evaluates_checkpoint_once(self):
        for est in self._estimators_for_tests(eval_dict={'global_step': 100}):
            est.fake_checkpoint()

            result = {
                'called': 0,
                'called_with_eval_result': 0,
            }

            # pylint: disable=cell-var-from-loop
            def _predicate_fn(eval_result):
                result['called'] += 1
                if eval_result:
                    # If eval_result is not empty nor None, the checkpoint has been
                    # evaluated.
                    result['called_with_eval_result'] += 1
                # With 300 times of evaluation, this should prove something.
                return result['called'] < 300

            # pylint: enable=cell-var-from-loop

            ex = Experiment(
                est,
                train_input_fn='train_input',
                eval_input_fn='eval_input',
                eval_delay_secs=0,
                continuous_eval_throttle_secs=0)
            ex.continuous_eval(evaluate_checkpoint_only_once=True,
                               continuous_eval_predicate_fn=_predicate_fn)

            self.assertEqual(0, est.fit_count)
            self.assertEqual(1, est.eval_count)
            self.assertEqual(300, result['called'])
            self.assertEqual(1, result['called_with_eval_result'])
示例#3
0
 def test_continuous_eval_ends_after_train_step(self):
     for est in self._estimators_for_tests(eval_dict={'global_step': 100}):
         est.fake_checkpoint()
         noop_hook = _NoopHook()
         ex = Experiment(est,
                         train_input_fn='train_input',
                         eval_input_fn='eval_input',
                         eval_hooks=[noop_hook],
                         eval_delay_secs=0,
                         continuous_eval_throttle_secs=0,
                         train_steps=100)
         ex.continuous_eval()
         self.assertEqual(0, est.fit_count)
         self.assertEqual(1, est.eval_count)
         self.assertEqual([noop_hook], est.eval_hooks)
示例#4
0
    def test_continuous_eval_predicate_fn(self):
        for est in self._estimators_for_tests():
            est.fake_checkpoint()
            noop_hook = _NoopHook()

            def _predicate_fn(unused_eval_result):
                return est.eval_count < 3  # pylint: disable=cell-var-from-loop

            ex = Experiment(est, train_input_fn='train_input', eval_input_fn='eval_input',
                            eval_hooks=[noop_hook], eval_delay_secs=0,
                            continuous_eval_throttle_secs=0)
            ex.continuous_eval(evaluate_checkpoint_only_once=False,
                               continuous_eval_predicate_fn=_predicate_fn)
            self.assertEqual(0, est.fit_count)
            self.assertEqual(3, est.eval_count)
            self.assertEqual([noop_hook], est.eval_hooks)
示例#5
0
 def test_continuous_eval_ends_after_train_step(self):
     for est in self._estimators_for_tests(eval_dict={'global_step': 100}):
         est.fake_checkpoint()
         noop_hook = _NoopHook()
         ex = Experiment(
             est,
             train_input_fn='train_input',
             eval_input_fn='eval_input',
             eval_hooks=[noop_hook],
             eval_delay_secs=0,
             continuous_eval_throttle_secs=0,
             train_steps=100)
         ex.continuous_eval()
         self.assertEqual(0, est.fit_count)
         self.assertEqual(1, est.eval_count)
         self.assertEqual([noop_hook], est.eval_hooks)
示例#6
0
    def test_continuous_eval_predicate_fn(self):
        for est in self._estimators_for_tests():
            est.fake_checkpoint()
            noop_hook = _NoopHook()

            def _predicate_fn(unused_eval_result):
                return est.eval_count < 3  # pylint: disable=cell-var-from-loop

            ex = Experiment(est,
                            train_input_fn='train_input',
                            eval_input_fn='eval_input',
                            eval_hooks=[noop_hook],
                            eval_delay_secs=0,
                            continuous_eval_throttle_secs=0)
            ex.continuous_eval(evaluate_checkpoint_only_once=False,
                               continuous_eval_predicate_fn=_predicate_fn)
            self.assertEqual(0, est.fit_count)
            self.assertEqual(3, est.eval_count)
            self.assertEqual([noop_hook], est.eval_hooks)