-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclean_wandb.py
More file actions
executable file
·58 lines (49 loc) · 1.52 KB
/
clean_wandb.py
File metadata and controls
executable file
·58 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#%%
import os
from os.path import join
from glob import glob
import shutil
import wandb
from os.path import exists
import yaml
assert exists('.wandb_config/setup.yaml'), "Please configure your wandb settings first."
with open('.wandb_config/setup.yaml', 'r') as stream:
wandb_config = yaml.safe_load(stream)
wandb_project = f"{wandb_config['entity']}/{wandb_config['project']}"
print(f"==> Project: {wandb_project}")
api = wandb.Api()
runs = api.runs(wandb_project)
log_dir = 'logs'
print('!!! Carefully check: ', runs, '<=>', log_dir, ' !!!')
runs_remote = []
for run in runs:
runs_remote.append(run.name)
exclude_list = ['figures']
runs_local = glob(join(log_dir, '*'))
for runs_local_folder in runs_local:
if os.path.basename(runs_local_folder) in exclude_list:
runs_local.remove(runs_local_folder)
# print("="*20)
# print("The following runs will be removed:")
cnt_removed = 0
for run in runs_local:
if run.split('/')[-1] not in runs_remote:
print(run)
cnt_removed += 1
# print("="*20)
# print("The following runs will NOT be removed:")
cnt_kept = 0
for run in runs_local:
if run.split('/')[-1] in runs_remote:
# print(run)
cnt_kept += 1
# print("="*20)
print(f"Total {len(runs_local)} runs, {cnt_removed} will be removed, {cnt_kept} will be kept.")
confirm = input("Confirm you want to delete them? y/[n]:")
if confirm == 'y':
for run in runs_local:
if run.split('/')[-1] not in runs_remote:
shutil.rmtree(run)
print('Deleted.')
else:
print('Aborted.')