-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModelLoad.py
More file actions
58 lines (47 loc) · 1.46 KB
/
ModelLoad.py
File metadata and controls
58 lines (47 loc) · 1.46 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
#!/usr/bin/Python3
'''
根据时间戳来自动的加载模型加载最新的模型
'''
import os
import re
path_model_dir = "model"
def get_info(path):
names = []
paths = []
for root, dir, files in os.walk(path):
for f in files:
names.append(f)
p = os.path.join(root, f)
paths.append(p)
return names, paths
def get_best_model(path): # 获取最好的模型
names, paths = get_info(path)
names_paths = dict(zip(names, paths))
accs = []
for na in names:
result = re.findall(r"-(.*).c", na)[0]
result = result.split("-")[-1]
accs.append(float(result))
name_accs = dict(zip(names, accs))
name_accs = sorted(name_accs.items(), key=lambda x: -x[1])
top_name = name_accs[0]
top_name = top_name[0]
path = names_paths[top_name]
print("Loading model path:{}".format(path))
return path
def get_new_model(path): # 获得的是最新的模型
names, paths = get_info(path)
names_paths = dict(zip(names, paths))
accs = []
for na in names:
result = re.findall(r"-(.*).c", na)[0]
result = result.split('-')[1]
accs.append(float(result))
name_accs = dict(zip(names, accs))
name_accs = sorted(name_accs.items(), key=lambda x: -x[1])
top_name = name_accs[0]
top_name = top_name[0]
path = names_paths[top_name]
print("Loading model path:{}".format(path))
return path
# print(get_new_model(path_model_dir))