-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_training.py
More file actions
71 lines (54 loc) · 1.97 KB
/
run_training.py
File metadata and controls
71 lines (54 loc) · 1.97 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import glob
from time import sleep
import model_main as train
import tensorflow as tf
from absl import flags
import os
import time
def main():
TrainingsStepsBeforeCheck = 18000
print("initialse autotraining...")
subdirectory = "trainingdata"
folders_in_subdirectory_old = []
while 1:
folders_in_subdirectory_new = getFoldersInSubdirecory(subdirectory)
missing_folders = makeNewList(folders_in_subdirectory_new, folders_in_subdirectory_old)
folders_in_subdirectory_old = getFoldersInSubdirecory(subdirectory)
flags.FLAGS([""])
for folder in missing_folders:
try:
configpath = glob.glob(os.path.join(folder, "*.config"))[0]
flags.FLAGS.pipeline_config_path = configpath
flags.FLAGS.model_dir = "training"
flags.FLAGS.num_train_steps = TrainingsStepsBeforeCheck
print(folder)
print(flags.FLAGS.model_dir)
initialTime = int(time.time())
while True:
runTrainJob()
flags.FLAGS.num_train_steps += 18000
elapsedTime = time.time() - initialTime
if(elapsedTime > 60 * 60 * 6):
break
except OSError as e:
print(e)
except IOError:
print("Error occurred with %s. Try next config.." % folder)
sleep(2)
print("Waiting for new folder...")
def getFoldersInSubdirecory(path):
folders_in_subdirectory = [os.path.join(path, o)
for o in os.listdir(path)
if os.path.isdir(os.path.join(path, o))]
return folders_in_subdirectory
# @asyncio.coroutine
def runTrainJob():
try:
tf.app.run(train.main)
except SystemExit as e:
pass
def makeNewList(list_new, list_old):
new_list = [i for i in list_new if i not in list_old]
return new_list
if __name__ == '__main__':
main()