forked from neuroailab/Neural-Alignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
45 lines (36 loc) · 1.14 KB
/
train.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
'''
Trains neural-alignment models
All options should be configured via flags
'''
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import absl.logging as _logging
import os
import tensorflow as tf
from tfutils import base
import flags
from params import Params
FLAGS = flags.FLAGS
#### Actual training
def main(argv):
os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpu
del argv # Unused
params = Params()
if FLAGS.load_params_file is not None:
assert(FLAGS.load_params_file[-4:] == '.pkl')
print("Loading params from file: {}".format(FLAGS.load_params_file))
print("Ignoring all config flags")
params.load(FLAGS.load_params_file, FLAGS)
else:
print("Parsing params from flags...")
params.customize(flags=FLAGS)
params_copy = params.get_params_copy()
print("All params: ")
print(params_copy)
if FLAGS.save_params_file is not None:
assert(FLAGS.save_params_file[-4:] == '.pkl')
params.save(FLAGS.save_params_file)
base.train_from_params(**params_copy)
if __name__ == '__main__':
tf.app.run(main)