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")
| 219 | |
| 220 | |
| 221 | def 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 | |
| 245 | def load_checkpoint_vars(path): |
nothing calls this directly
no test coverage detected
searching dependent graphs…