Skip to content

Instantly share code, notes, and snippets.

@dipta007
Last active May 11, 2022 22:48
Show Gist options
  • Select an option

  • Save dipta007/b072402a67a05ec7043f5dfd572ad74a to your computer and use it in GitHub Desktop.

Select an option

Save dipta007/b072402a67a05ec7043f5dfd572ad74a to your computer and use it in GitHub Desktop.
Create a backup of all codes during each run for reproducibility
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