MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CheckpointLoadStatus

Class CheckpointLoadStatus

tensorflow/python/training/tracking/util.py:669–837  ·  view source on GitHub ↗

Checks the status of checkpoint loading and manages restore ops. Returned from `Saver.restore`. Since `restore` may defer the loading of values in the checkpoint which don't yet have corresponding Python objects, `CheckpointLoadStatus` provides a callback to verify that checkpoint loading i

Source from the content-addressed store, hash-verified

667
668
669class CheckpointLoadStatus(_LoadStatus):
670 """Checks the status of checkpoint loading and manages restore ops.
671
672 Returned from `Saver.restore`. Since `restore` may defer the loading of values
673 in the checkpoint which don't yet have corresponding Python objects,
674 `CheckpointLoadStatus` provides a callback to verify that checkpoint loading
675 is complete (`assert_consumed`).
676
677 When graph building, `restore` does not run restore ops itself since their
678 creation may be deferred. The `run_restore_ops` method must be called once all
679 Python objects with values to restore have been created and added to the
680 dependency graph (this does not necessarily have to be the whole checkpoint;
681 calling `run_restore_ops` while `assert_consumed` fails is supported and will
682 partially restore the checkpoint).
683
684 See `Saver.restore` for usage examples.
685 """
686
687 def __init__(self, checkpoint, feed_dict, graph_view):
688 self._checkpoint = checkpoint
689 self._feed_dict = feed_dict
690 self._graph_view = graph_view
691 # Keep a reference to the root, since graph_view might only have a weakref.
692 self._root = graph_view.root
693
694 def assert_consumed(self):
695 """Asserts that all objects in the checkpoint have been created/matched.
696
697 Returns:
698 `self` for chaining.
699 Raises:
700 AssertionError: If there are any Python objects in the dependency graph
701 which have not been restored from this checkpoint or a later `restore`,
702 or if there are any checkpointed values which have not been matched to
703 Python objects.
704 """
705 pretty_printer = _ObjectGraphProtoPrettyPrinter(
706 self._checkpoint.object_graph_proto)
707 self.assert_existing_objects_matched()
708 for node_id, node in enumerate(self._checkpoint.object_graph_proto.nodes):
709 trackable = self._checkpoint.object_by_proto_id.get(node_id, None)
710 if trackable is None:
711 raise AssertionError("Unresolved object in checkpoint {}: {}"
712 .format(pretty_printer.node_names[node_id], node))
713 if self._checkpoint.slot_restorations:
714 # Sanity check; this collection should be clear if everything has been
715 # restored.
716 raise AssertionError("Unresolved slot restorations: %s" %
717 (self._checkpoint.slot_restorations,))
718 if self._checkpoint.unused_attributes:
719 unused_attribute_messages = []
720 for node_id, attribute in six.iteritems(
721 self._checkpoint.unused_attributes):
722 obj = self._checkpoint.object_by_proto_id[node_id]
723 unused_attribute_messages.append(
724 "{} ({}): {}"
725 .format(pretty_printer.node_names[node_id], obj, attribute))
726 raise AssertionError(

Callers 1

restoreMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected