(
self, return_numpy, enable_async_checkpoint_saving
)
| 393 | ("return_tensor_async_checkpoint_saving", False, True), |
| 394 | ) |
| 395 | def test_train_and_evaluate( |
| 396 | self, return_numpy, enable_async_checkpoint_saving |
| 397 | ): |
| 398 | test_runner = TestRunner(return_numpy=return_numpy) |
| 399 | |
| 400 | checkpoint = tf.train.Checkpoint( |
| 401 | model=test_runner.model, optimizer=test_runner.optimizer) |
| 402 | checkpoint_manager = tf.train.CheckpointManager( |
| 403 | checkpoint, |
| 404 | self.model_dir, |
| 405 | max_to_keep=None, |
| 406 | step_counter=test_runner.global_step, |
| 407 | checkpoint_interval=10) |
| 408 | test_controller = controller.Controller( |
| 409 | trainer=test_runner, |
| 410 | evaluator=test_runner, |
| 411 | global_step=test_runner.global_step, |
| 412 | steps_per_loop=2, |
| 413 | summary_dir=os.path.join(self.model_dir, "summaries/train"), |
| 414 | checkpoint_manager=checkpoint_manager, |
| 415 | enable_async_checkpointing=enable_async_checkpoint_saving, |
| 416 | eval_summary_dir=os.path.join(self.model_dir, "summaries/eval")) |
| 417 | test_controller.train_and_evaluate( |
| 418 | train_steps=10, eval_steps=2, eval_interval=6) |
| 419 | |
| 420 | # Checkpoints are saved. |
| 421 | self.assertNotEmpty(tf.io.gfile.glob(os.path.join(self.model_dir, "ckpt*"))) |
| 422 | |
| 423 | # Loss and accuracy values should be written into summaries. |
| 424 | self.assertNotEmpty( |
| 425 | tf.io.gfile.listdir(os.path.join(self.model_dir, "summaries/train"))) |
| 426 | self.assertNotEmpty( |
| 427 | summaries_with_matching_keyword( |
| 428 | "loss", os.path.join(self.model_dir, "summaries/train"))) |
| 429 | self.assertNotEmpty( |
| 430 | tf.io.gfile.listdir(os.path.join(self.model_dir, "summaries/eval"))) |
| 431 | self.assertNotEmpty( |
| 432 | summaries_with_matching_keyword( |
| 433 | "eval_loss", os.path.join(self.model_dir, "summaries/eval"))) |
| 434 | |
| 435 | @parameterized.named_parameters( |
| 436 | ("_sync_checkpoint_saving", False), |
nothing calls this directly
no test coverage detected