forked from martinkersner/train-CRF-RNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resume_training.py
47 lines (35 loc) · 1.04 KB
/
resume_training.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
#!/usr/bin/env python
# Martin Kersner, 2016/03/10
from __future__ import print_function
from __future__ import division
import sys
import os
import caffe
import subprocess
def main():
iter_num = process_arguments(sys.argv)
solver_state = 'models/train_iter_{}.solverstate'.format(iter_num)
solver = caffe.SGDSolver('solver.prototxt')
solver.solve(solver_state) # load even *.caffemodel
solver.net.set_mode_gpu()
solver.net.set_device(0)
test_interval = 1000
max_iter = 200000
FNULL = open(os.devnull, 'w')
for i in xrange(max_iter):
solver.step(1)
if i > 0 and (i % test_interval) == 0:
subprocess.call(['python', 'test_model.py', str(i)], stderr=FNULL)
def process_arguments(argv):
if len(argv) != 2:
help()
else:
iteration_num = argv[1]
return iteration_num
def help():
print('Usage: python resume_training.py ITERATION_NUM\n' \
'ITERATION_NUM denotes iteration number of model which shall be tested.'
, file=sys.stderr)
exit()
if __name__ == '__main__':
main()