-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunc_utils.py
More file actions
38 lines (31 loc) · 1.06 KB
/
Copy pathfunc_utils.py
File metadata and controls
38 lines (31 loc) · 1.06 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
import os
import json
import argparse
def save_opt_to_json(opt, mpath):
json_dir = os.path.join(mpath, "opt.json")
argparse_dict = vars(opt)
with open(json_dir, 'w') as outfile:
json.dump(argparse_dict, outfile)
print ("configs have been dumped into %s" % json_dir)
def load_json_as_argparse(mpath):
try:
json_dir = os.path.join(mpath, "opt.json")
js = open(json_dir).read()
data = json.loads(js)
opt = argparse.Namespace()
for key, val in data.items():
setattr(opt, key, val)
return opt
except Exception as e:
print("No such file or directory %s" % (json_dir))
# auto find the most recent model, used in ComputeMI and plot_utils
def find_newest_model(mpath):
all_subdirs = []
for d in os.listdir(mpath):
bd = os.path.join(mpath, d)
if os.path.isdir(bd): all_subdirs.append(bd)
latest_subdir = max(all_subdirs, key=os.path.getmtime)
mname = os.path.split(latest_subdir)[-1]
return mname, latest_subdir
if __name__ == "__main__":
pass