|
23 | 23 | import time |
24 | 24 |
|
25 | 25 | import tensorflow.compat.v1 as tf |
| 26 | +import tensorflow.compat.v2 as tf2 |
26 | 27 |
|
27 | 28 | from object_detection import eval_util |
28 | 29 | from object_detection import inputs |
@@ -414,8 +415,9 @@ def train_loop( |
414 | 415 | train_steps=None, |
415 | 416 | use_tpu=False, |
416 | 417 | save_final_config=False, |
417 | | - checkpoint_every_n=5000, |
| 418 | + checkpoint_every_n=1000, |
418 | 419 | checkpoint_max_to_keep=7, |
| 420 | + record_summaries=True, |
419 | 421 | **kwargs): |
420 | 422 | """Trains a model using eager + functions. |
421 | 423 |
|
@@ -445,6 +447,7 @@ def train_loop( |
445 | 447 | Checkpoint every n training steps. |
446 | 448 | checkpoint_max_to_keep: |
447 | 449 | int, the number of most recent checkpoints to keep in the model directory. |
| 450 | + record_summaries: Boolean, whether or not to record summaries. |
448 | 451 | **kwargs: Additional keyword arguments for configuration override. |
449 | 452 | """ |
450 | 453 | ## Parse the configs |
@@ -531,8 +534,11 @@ def train_dataset_fn(input_context): |
531 | 534 | # is the chief. |
532 | 535 | summary_writer_filepath = get_filepath(strategy, |
533 | 536 | os.path.join(model_dir, 'train')) |
534 | | - summary_writer = tf.compat.v2.summary.create_file_writer( |
535 | | - summary_writer_filepath) |
| 537 | + if record_summaries: |
| 538 | + summary_writer = tf.compat.v2.summary.create_file_writer( |
| 539 | + summary_writer_filepath) |
| 540 | + else: |
| 541 | + summary_writer = tf2.summary.create_noop_writer() |
536 | 542 |
|
537 | 543 | if use_tpu: |
538 | 544 | num_steps_per_iteration = 100 |
@@ -604,7 +610,9 @@ def _dist_train_step(data_iterator): |
604 | 610 |
|
605 | 611 | if num_steps_per_iteration > 1: |
606 | 612 | for _ in tf.range(num_steps_per_iteration - 1): |
607 | | - _sample_and_train(strategy, train_step_fn, data_iterator) |
| 613 | + # Following suggestion on yaqs/5402607292645376 |
| 614 | + with tf.name_scope(''): |
| 615 | + _sample_and_train(strategy, train_step_fn, data_iterator) |
608 | 616 |
|
609 | 617 | return _sample_and_train(strategy, train_step_fn, data_iterator) |
610 | 618 |
|
|
0 commit comments