build() with option to only perform save and restore.
(self,
names_to_saveables,
reshape=False,
sharded=False,
max_to_keep=5,
keep_checkpoint_every_n_hours=10000.0,
name=None,
restore_sequentially=False,
filename="model",
build_save=True,
build_restore=True)
| 616 | filename=filename) |
| 617 | |
| 618 | def _build_internal(self, |
| 619 | names_to_saveables, |
| 620 | reshape=False, |
| 621 | sharded=False, |
| 622 | max_to_keep=5, |
| 623 | keep_checkpoint_every_n_hours=10000.0, |
| 624 | name=None, |
| 625 | restore_sequentially=False, |
| 626 | filename="model", |
| 627 | build_save=True, |
| 628 | build_restore=True): |
| 629 | """build() with option to only perform save and restore.""" |
| 630 | if not context.executing_eagerly() and (not build_save or |
| 631 | not build_restore): |
| 632 | raise ValueError("save and restore operations need to be built together " |
| 633 | " when eager execution is not enabled.") |
| 634 | |
| 635 | saveables = saveable_object_util.validate_and_slice_inputs( |
| 636 | names_to_saveables) |
| 637 | if max_to_keep is None: |
| 638 | max_to_keep = 0 |
| 639 | |
| 640 | with ops.name_scope(name, "save", |
| 641 | [saveable.op for saveable in saveables]) as name: |
| 642 | # Add a placeholder string tensor for the filename. |
| 643 | filename_tensor = array_ops.placeholder_with_default( |
| 644 | filename or "model", shape=(), name="filename") |
| 645 | # Keep the name "Const" for backwards compatibility. |
| 646 | filename_tensor = array_ops.placeholder_with_default( |
| 647 | filename_tensor, shape=(), name="Const") |
| 648 | self.filename_tensor = filename_tensor |
| 649 | |
| 650 | # Add the save ops. |
| 651 | if sharded: |
| 652 | per_device = self._GroupByDevices(saveables) |
| 653 | if build_save: |
| 654 | save_tensor = self._AddShardedSaveOps(filename_tensor, per_device) |
| 655 | if build_restore: |
| 656 | restore_op = self._AddShardedRestoreOps(filename_tensor, per_device, |
| 657 | restore_sequentially, reshape) |
| 658 | else: |
| 659 | if build_save: |
| 660 | save_tensor = self._AddSaveOps(filename_tensor, saveables) |
| 661 | if build_restore: |
| 662 | restore_op = self._AddRestoreOps(filename_tensor, saveables, |
| 663 | restore_sequentially, reshape) |
| 664 | |
| 665 | # In the following use case, it's possible to have restore_ops be called |
| 666 | # something else: |
| 667 | # - Build inference graph and export a meta_graph. |
| 668 | # - Import the inference meta_graph |
| 669 | # - Extend the inference graph to a train graph. |
| 670 | # - Export a new meta_graph. |
| 671 | # Now the second restore_op will be called "restore_all_1". |
| 672 | # As such, comment out the assert for now until we know whether supporting |
| 673 | # such usage model makes sense. |
| 674 | # |
| 675 | # assert restore_op.name.endswith("restore_all"), restore_op.name |
no test coverage detected