In simple terms, the job of tf.app.run()
is to first set the global flags for later usage like:
from tensorflow.python.platform import flags
f = flags.FLAGS
and then run your custom main function with a set of arguments.
For e.g. in TensorFlow NMT codebase, the very first entry point for the program execution for training/inference starts at this point (see below code)
if __name__ == "__main__":
nmt_parser = argparse.ArgumentParser()
add_arguments(nmt_parser)
FLAGS, unparsed = nmt_parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
After parsing the arguments using argparse
, with tf.app.run()
you run the function "main" which is defined like:
def main(unused_argv):
default_hparams = create_hparams(FLAGS)
train_fn = train.train
inference_fn = inference.inference
run_main(FLAGS, default_hparams, train_fn, inference_fn)
So, after setting the flags for global use, tf.app.run()
simply runs that main
function that you pass to it with argv
as its parameters.