(self)
| 471 | tf.io.gfile.exists(os.path.join(self.model_dir, "summaries/eval"))) |
| 472 | |
| 473 | def test_evaluate_only(self): |
| 474 | test_runner = TestRunner() |
| 475 | |
| 476 | checkpoint = tf.train.Checkpoint(model=test_runner.model) |
| 477 | checkpoint.save(os.path.join(self.model_dir, "ckpt")) |
| 478 | checkpoint_manager = tf.train.CheckpointManager( |
| 479 | checkpoint, |
| 480 | self.model_dir, |
| 481 | max_to_keep=None, |
| 482 | step_counter=test_runner.global_step) |
| 483 | test_controller = controller.Controller( |
| 484 | evaluator=test_runner, |
| 485 | global_step=test_runner.global_step, |
| 486 | checkpoint_manager=checkpoint_manager, |
| 487 | summary_dir=os.path.join(self.model_dir, "summaries/train"), |
| 488 | eval_summary_dir=os.path.join(self.model_dir, "summaries/eval")) |
| 489 | eval_results = test_controller.evaluate(steps=2) |
| 490 | |
| 491 | # Only eval summaries are written |
| 492 | self.assertFalse( |
| 493 | tf.io.gfile.exists(os.path.join(self.model_dir, "summaries/train"))) |
| 494 | self.assertNotEmpty( |
| 495 | tf.io.gfile.listdir(os.path.join(self.model_dir, "summaries/eval"))) |
| 496 | self.assertNotEmpty( |
| 497 | summaries_with_matching_keyword( |
| 498 | "eval_loss", os.path.join(self.model_dir, "summaries/eval"))) |
| 499 | self.assertIn("eval_loss", eval_results) |
| 500 | |
| 501 | # Tests continuous eval with timeout and timeout_fn. |
| 502 | done_file = os.path.join(self.model_dir, "summaries/eval/Done") |
| 503 | |
| 504 | def timeout_fn(): |
| 505 | with tf.io.gfile.GFile(done_file, "w") as f: |
| 506 | f.write("DONE") |
| 507 | return True |
| 508 | |
| 509 | test_controller = controller.Controller( |
| 510 | evaluator=test_runner, |
| 511 | global_step=test_runner.global_step, |
| 512 | checkpoint_manager=checkpoint_manager, |
| 513 | eval_summary_dir=os.path.join(self.model_dir, "summaries/eval")) |
| 514 | test_controller.evaluate_continuously( |
| 515 | timeout=1, timeout_fn=timeout_fn, steps=2) |
| 516 | self.assertNotEmpty(tf.io.gfile.glob(done_file)) |
| 517 | |
| 518 | def test_no_eval_steps(self): |
| 519 | test_runner = TestRunner() |
nothing calls this directly
no test coverage detected