-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (21 loc) · 685 Bytes
/
utils.py
File metadata and controls
29 lines (21 loc) · 685 Bytes
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
import os
import glob
def mkpath(path):
if not os.path.exists(path):
os.makedirs(path)
return path + '/'
def get_epoch(x):
return int(x.split('.')[1].split('_')[2])
def get_last_epoch(weight_path):
weights = sorted(glob.glob(os.path.join(
weight_path, 'weight.*.h5')), key=get_epoch)
last_weight = weights[-1] if weights else None
last_epoch = get_epoch(last_weight) if last_weight else 0
return last_weight, last_epoch
def get_weight_at_epoch(weight_path, epoch):
weights = glob.glob(os.path.join(
weight_path, 'weight.*.h5'))
for w in weights:
if get_epoch(w) == epoch:
return w
return None