-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8733487
commit 9ffeba9
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Script to package logs from experiment directory. | ||
Example usage: | ||
python3 package_logs.py --experiment_dir <experiment_dir> --destination_dir <destination_dir> | ||
""" | ||
from absl import flags | ||
from absl import app | ||
|
||
import os | ||
import shutil | ||
|
||
flags.DEFINE_string('experiment_dir', None, 'Path to experiment.') | ||
flags.DEFINE_string('destination_dir', None, 'Path to save submission logs') | ||
|
||
FLAGS = flags.FLAGS | ||
|
||
def move_logs(experiment_dir, destination_dir): | ||
"""Copy files from experiment path to destination directory. | ||
Args: | ||
experiment_dir: Path to experiment dir. | ||
destination_dir: Path to destination dir. | ||
""" | ||
print('in move logs') | ||
print(destination_dir) | ||
if not os.path.exists(experiment_dir): | ||
raise IOError(f'Directory does not exist {destination_dir}') | ||
|
||
for root, dirnames, filenames in os.walk(experiment_dir): | ||
for filename in filenames: | ||
if 'checkpoint' not in filename: | ||
source_path = os.path.join(root, filename) | ||
relative_path = os.path.relpath(source_path, experiment_dir) | ||
destination_path = os.path.join(destination_dir, relative_path) | ||
os.makedirs(os.path.dirname(destination_path), exist_ok=True) | ||
print(f'Moving {source_path} to {destination_path}') | ||
shutil.copy(source_path, destination_path) | ||
|
||
|
||
def main(_): | ||
flags.mark_flag_as_required('destination_dir') | ||
flags.mark_flag_as_required('experiment_dir') | ||
move_logs(FLAGS.experiment_dir, FLAGS.destination_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(main) |