-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
executable file
·32 lines (25 loc) · 1.04 KB
/
tools.py
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
import os
import glob
def obtain_default_model(cfg):
dates = os.listdir(f'./experiments/{cfg["data"]["type"]}')
dates.sort(reverse=True)
folders = os.listdir(f'./experiments/{cfg["data"]["type"]}/{dates[0]}/{cfg["model"]}')
folders.sort(reverse=True)
model_path = ''
for model in glob.glob(f'./experiments/{cfg["data"]["type"]}/{dates[0]}/'
f'{cfg["model"]}/{folders[0]}/train/*.pth.tar'):
if 'model_best' in model:
model_path = model
return model_path
def obtain_ckpt_by_epoch(cfg, epoch):
dates = os.listdir(f'./experiments/{cfg["data"]["type"]}')
dates.sort(reverse=True)
folders = os.listdir(f'./experiments/{cfg["data"]["type"]}/{dates[0]}/{cfg["model"]}')
folders.sort(reverse=True)
model_path = ''
import glob
for model in glob.glob(f'./experiments/{cfg["data"]["type"]}/{dates[0]}/'
f'{cfg["model"]}/{folders[0]}/train/*.pth.tar'):
if str(epoch).zfill(3) in model:
model_path = model
return model_path