Copies a checkpoint to a new directory. Args: checkpoint_path: Specific checkpoint path to copy. to_dir: The target directory to copy to. to_checkpoint_name: The target checkpoint name to copy to. Raises: NotFoundError: When the given checkpoint is not found.
(checkpoint_path,
to_dir,
to_checkpoint_name = BEST_CHECKPOINT_FILENAME)
| 28 | |
| 29 | |
| 30 | def copy_checkpoint(checkpoint_path, |
| 31 | to_dir, |
| 32 | to_checkpoint_name = BEST_CHECKPOINT_FILENAME): |
| 33 | """Copies a checkpoint to a new directory. |
| 34 | |
| 35 | Args: |
| 36 | checkpoint_path: Specific checkpoint path to copy. |
| 37 | to_dir: The target directory to copy to. |
| 38 | to_checkpoint_name: The target checkpoint name to copy to. |
| 39 | |
| 40 | Raises: |
| 41 | NotFoundError: When the given checkpoint is not found. |
| 42 | """ |
| 43 | if not checkpoint_path: |
| 44 | raise tf.errors.NotFoundError(None, None, |
| 45 | "Checkpoint path must be non-empty") |
| 46 | old_filenames = tf.io.gfile.glob(checkpoint_path + "*") |
| 47 | if not old_filenames: |
| 48 | raise tf.errors.NotFoundError( |
| 49 | None, None, "Unable to find checkpoint: %s" % checkpoint_path) |
| 50 | |
| 51 | if not tf.io.gfile.exists(to_dir): |
| 52 | tf.io.gfile.makedirs(to_dir) |
| 53 | |
| 54 | # Threaded copying helps to mitigate issues where large checkpoints do not |
| 55 | # finish copying before being deleted. |
| 56 | threads = [] |
| 57 | executor = concurrent.futures.ThreadPoolExecutor(max_workers=20) |
| 58 | for old_filename in old_filenames: |
| 59 | _, suffix = os.path.splitext(old_filename) |
| 60 | new_filename = os.path.join(to_dir, to_checkpoint_name + suffix) |
| 61 | threads.append( |
| 62 | executor.submit( |
| 63 | tf.io.gfile.copy, old_filename, new_filename, overwrite=True)) |
| 64 | concurrent.futures.wait(threads) |
| 65 | tf.logging.info("Copied checkpoint %s to dir %s", checkpoint_path, to_dir) |
| 66 | |
| 67 | # Recreates a checkpoint file. |
| 68 | new_checkpoint = os.path.join(to_dir, to_checkpoint_name) |
| 69 | tf.train.update_checkpoint_state(to_dir, new_checkpoint) |
| 70 | tf.logging.info("Writing new checkpoint file for %s", to_dir) |
| 71 | |
| 72 | |
| 73 | def update_eval_info( |
no test coverage detected
searching dependent graphs…