Last active
May 11, 2022 22:48
-
-
Save dipta007/b072402a67a05ec7043f5dfd572ad74a to your computer and use it in GitHub Desktop.
Create a backup of all codes during each run for reproducibility
This file contains hidden or 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
| from zipfile import ZipFile | |
| import os | |
| EXCLUDE = ['./wandb', './.history', './data', './__pycache__', './results', './models', | |
| './logs', './config.json', './saved_configs', './saved_models', './.ipynb_checkpoints'] | |
| INCLUDE = ['.py', '.sh'] | |
| def create(filename): | |
| not_excluded = lambda root: not any(root.startswith(path) for path in EXCLUDE) | |
| included = lambda root: any(root.endswith(ext) for ext in INCLUDE) | |
| with ZipFile(filename, 'w') as myzip: | |
| for root, dirs, files in os.walk('./'): | |
| for file in files: | |
| if not_excluded(root) and included(file): | |
| # print(root, file) | |
| myzip.write(os.path.join(root, file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment