forked from Intel-tensorflow/Tensorflow-SSD-VGG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_all_checkpoints.py
95 lines (72 loc) · 3 KB
/
run_all_checkpoints.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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import re
import argparse
class RunAllCheckpoints(object):
def __init__(self):
return
def get_all_checkpoints(self,checkpoint_path):
with open(self.checkpoint_path + "checkpoint") as f:
content = f.readlines()
content = [x.strip() for x in content]
checkpoints = []
for line in content:
m = re.search('all_model_checkpoint_paths: "model.ckpt-(.*)"', line)
if m:
num = m.group(1)
checkpoints.append(num)
min_step = 30000
step = 10000
last_step = min_step
sel_checkpoints = []
for checkpoint in checkpoints:
checkpoint = int(checkpoint)
if checkpoint < min_step:
continue
if checkpoint == int(checkpoints[-1]):
#the last checkpoint always get selected
sel_checkpoints.append(checkpoint)
continue
if checkpoint >= last_step:
sel_checkpoints.append(checkpoint)
last_step = last_step + step
if self.check_only_latest:
#if we only want to evluate the latest checkpoints
sel_checkpoints = [sel_checkpoints[-1]]
return sel_checkpoints
def parse_param(self):
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--finetune', help='whether use checkpoints under finetune folder', action='store_true')
parser.add_argument('-l', '--latest', help='evaluate only the latest checkpoints', action='store_true')
args = parser.parse_args()
self.checkpoint_path = './logs/'
if args.finetune:
self.checkpoint_path = './logs/finetune/'
self.check_only_latest = args.latest
return
def run_all_checkpoints(self):
self.parse_param()
sel_checkpoints = self.get_all_checkpoints(self.checkpoint_path)
self.eval_during_training = False;
self.eval_one_time = True
for checkpoint in sel_checkpoints:
for eval_train in [True, False]:
checkpoint_file = self.checkpoint_path + "model.ckpt-" + str(checkpoint)
if eval_train:
data = "train"
else:
data = "test"
print("checkpoint {}, {} data".format(checkpoint_file, data))
cmd_str = "python ./evaluate_model.py "
if eval_train:
cmd_str = cmd_str + " -t "
# cmd_str = cmd_str + " -c " + self.checkpoint_path
cmd_str = '{} -c "{}"'.format(cmd_str, checkpoint_file)
os.system(cmd_str)
return
def run(self):
self.parse_param()
self.run_all_checkpoints()
return
if __name__ == "__main__":
obj= RunAllCheckpoints()
obj.run()