-
Notifications
You must be signed in to change notification settings - Fork 123
/
train_hook.py
39 lines (30 loc) · 916 Bytes
/
train_hook.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
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
# File Name : train_hook.py
# Purpose :
# Creation Date : 14-12-2017
# Last Modified : Sat 23 Dec 2017 11:45:38 PM CST
# Created By : Jeasine Ma [jeasinema[at]gmail[dot]com]
import os
import argparse
import pickle
import numpy as np
def check_if_should_pause(tag):
fname = tag + '.pause.pkl'
ret = False
if os.path.exists(fname):
s = pickle.load(open(tag + '.pause.pkl', 'rb'))
if s == 'pause':
ret = True
os.remove(fname)
return ret
def pause_trainer(args):
fname = args.tag + '.pause.pkl'
if os.path.exists(fname):
os.remove(fname)
pickle.dump('pause', open(fname, 'wb'))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='training')
parser.add_argument('--tag', type=str, nargs='?', default='default')
args = parser.parse_args()
pause_trainer(args)