MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / get_all_checkpoints

Function get_all_checkpoints

tensorpack/tfutils/varmanip.py:221–242  ·  view source on GitHub ↗

Get a sorted list of all checkpoints found in directory. Args: dir (str): checkpoint directory prefix (str): common prefix among all checkpoints (without the final "-") Returns: list[(str, int)]: list of (name, step) sorted by step. Name is a checkpoint

(dir: str, prefix: str = "model")

Source from the content-addressed store, hash-verified

219
220
221def get_all_checkpoints(dir: str, prefix: str = "model"):
222 """
223 Get a sorted list of all checkpoints found in directory.
224
225 Args:
226 dir (str): checkpoint directory
227 prefix (str): common prefix among all checkpoints (without the final "-")
228
229 Returns:
230 list[(str, int)]: list of (name, step) sorted by step.
231 Name is a checkpoint handle that can be passed to
232 `tf.train.NewCheckpointReader` or :func:`load_checkpoint_vars`.
233 """
234 def step_from_filename(name):
235 name = os.path.basename(name)
236 name = name[len(f"{prefix}-"):-len(".index")]
237 return int(name)
238
239 checkpoints = glob.glob(os.path.join(dir, "model-*.index"))
240 checkpoints = [(f, step_from_filename(f)) for f in checkpoints]
241 checkpoints = sorted(checkpoints, key=operator.itemgetter(1))
242 return checkpoints
243
244
245def load_checkpoint_vars(path):

Callers

nothing calls this directly

Calls 2

step_from_filenameFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…