forked from thunlp/TensorFlow-Summarization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.py
More file actions
43 lines (33 loc) · 1.24 KB
/
train.py
File metadata and controls
43 lines (33 loc) · 1.24 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
import tensorflow as tf
import subprocess
import logging
import os
MAX_STEPS = 300000
STEPS_PER_VALIDATION = 1000
STEPS_PER_CHECKPOINT = 20000
TEST_THRESHOLD = 200000
train_params = {
"--steps_per_validation": STEPS_PER_VALIDATION,
"--steps_per_checkpoint": STEPS_PER_CHECKPOINT,
}
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s",
datefmt='%b %d %H:%M')
try:
global_step = tf.contrib.framework.load_variable("model", "global_step")
except:
global_step = 0
logging.info("Training starts with global_step={}. ".format(global_step))
while global_step < MAX_STEPS:
terminate_step = max(global_step + STEPS_PER_CHECKPOINT, TEST_THRESHOLD)
logging.info("Train from {} to {}. ".format(
global_step, terminate_step))
proc = ["python3", "src/summarization.py",
"--max_iter", str(terminate_step)]
for key, val in train_params.items():
proc.append(key)
proc.append(str(val))
subprocess.call(proc)
global_step = terminate_step
subprocess.call(["python3", "script/test.py"])