Code style fixes for run.py
@@ -3,9 +3,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
-from six.moves import range
-import tensorflow as tf
import datetime
import argparse
import ast
@@ -16,6 +14,10 @@ import os
import sys
import shutil
+import tensorflow as tf
+from six.moves import range
+
+
from open_seq2seq.utils.utils import deco_print, flatten_dict, \
nest_dict, nested_update, get_git_diff, \
get_git_hash, Logger
@@ -66,9 +68,10 @@ def main():
# with command line arguments that were passed to the script
parser_unk = argparse.ArgumentParser()
for pm, value in flatten_dict(base_config).items():
- if type(value) is int or type(value) is float or type(value) is str:
+ if isinstance(value, int) or isinstance(value, float) or \
+ isinstance(value, str):
parser_unk.add_argument('--' + pm, default=value, type=type(value))
- elif type(value) is bool:
+ elif isinstance(value, bool):
parser_unk.add_argument('--' + pm, default=value, type=ast.literal_eval)
config_update = parser_unk.parse_args(unknown)
nested_update(base_config, nest_dict(vars(config_update)))
@@ -116,7 +119,9 @@ def main():
)
else:
raise IOError(
- "{} does not exist or is empty, can't restore model".format(ckpt_dir)
+ "{} does not exist or is empty, can't restore model".format(
+ ckpt_dir
+ )
)
except IOError as e:
if args.no_dir_check:
@@ -144,10 +149,12 @@ def main():
os.path.join(logdir, 'config_{}.py'.format(tm_suf)),
)
- with open(os.path.join(logdir, 'cmd-args_{}.log'.format(tm_suf)), 'w') as f:
+ with open(os.path.join(logdir, 'cmd-args_{}.log'.format(tm_suf)),
+ 'w') as f:
f.write(" ".join(sys.argv))
- with open(os.path.join(logdir, 'git-info_{}.log'.format(tm_suf)), 'w') as f:
+ with open(os.path.join(logdir, 'git-info_{}.log'.format(tm_suf)),
+ 'w') as f:
f.write('commit hash: {}'.format(get_git_hash()))
f.write(get_git_diff())
