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

Method save

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

Save a training checkpoint. The saved checkpoint includes variables created by this object and any Trackable objects it depends on at the time `Saver.save()` is called. Args: file_prefix: A prefix to use for the checkpoint filenames (/path/to/directory/and_a_prefix). Name

(self, file_prefix, checkpoint_number=None, session=None)

Source from the content-addressed store, hash-verified

1108 return self._cached_save_operation, feed_additions
1109
1110 def save(self, file_prefix, checkpoint_number=None, session=None):
1111 """Save a training checkpoint.
1112
1113 The saved checkpoint includes variables created by this object and any
1114 Trackable objects it depends on at the time `Saver.save()` is called.
1115
1116 Args:
1117 file_prefix: A prefix to use for the checkpoint filenames
1118 (/path/to/directory/and_a_prefix). Names are generated based on this
1119 prefix and `checkpoint_number`, if provided.
1120 checkpoint_number: An integer variable or Tensor, used to number
1121 checkpoints. Typically this value is saved along with other variables in
1122 training checkpoints, which will happen automatically if it was created
1123 by `root_trackable` or one of its dependencies (via
1124 `Trackable._add_variable`).
1125 session: The session to evaluate variables in. Ignored when executing
1126 eagerly. If not provided when graph building, the default session is
1127 used.
1128
1129 Returns:
1130 The full path to the checkpoint.
1131 """
1132 feed_dict = {}
1133 use_session = (not context.executing_eagerly() and
1134 not ops.inside_function())
1135 if checkpoint_number:
1136 file_prefix = "%s-%d" % (file_prefix, checkpoint_number)
1137 if use_session:
1138 if self._object_graph_feed_tensor is None:
1139 with ops.device("/cpu:0"):
1140 self._object_graph_feed_tensor = constant_op.constant(
1141 "", dtype=dtypes.string)
1142 self._file_prefix_feed_tensor = constant_op.constant(
1143 "", dtype=dtypes.string)
1144 object_graph_tensor = self._object_graph_feed_tensor
1145 file_prefix_tensor = self._file_prefix_feed_tensor
1146 feed_dict[file_prefix_tensor] = file_prefix
1147 else:
1148 with ops.device("/cpu:0"):
1149 file_prefix_tensor = constant_op.constant(
1150 file_prefix, dtype=dtypes.string)
1151 object_graph_tensor = None
1152
1153 file_io.recursive_create_dir(os.path.dirname(file_prefix))
1154 save_path, new_feed_additions = self._save_cached_when_graph_building(
1155 file_prefix=file_prefix_tensor, object_graph_tensor=object_graph_tensor)
1156 if new_feed_additions:
1157 feed_dict.update(new_feed_additions)
1158 if not use_session:
1159 session = None
1160 elif session is None:
1161 session = get_session()
1162
1163 if session:
1164 return session.run(save_path, feed_dict=feed_dict)
1165 else:
1166 return save_path
1167

Callers 1

saveFunction · 0.95

Calls 7

executing_eagerlyMethod · 0.80
get_sessionFunction · 0.70
deviceMethod · 0.45
constantMethod · 0.45
updateMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected